【问题标题】:How to read Model values and send them by ajax post如何读取模型值并通过 ajax post 发送它们
【发布时间】:2011-02-17 06:43:23
【问题描述】:

我有以下代码,它指出错误如下

错误 1 ​​当前上下文中不存在名称“日期”
错误 2 当前上下文中不存在名称 'person'

怎么了?

 $("#test").Click(function () {
            var date = $("#DateFrom").val();
            var person = Model.SelectedPerson;

            $.ajax({
                url: '@Url.Action("testEmp","Employee",new {dateFrom = date, selectedPerson= person})',
                type: 'GET',
                contentType: "application/json; charset=utf-8",
                dataType: "html",
                success: function (result) {
                    $('#text).html(result);
                },
                              });
            return false;
        });

【问题讨论】:

    标签: asp.net asp.net-mvc asp.net-mvc-3


    【解决方案1】:

    试试这个:

    $.ajax({
        url: '@Url.Action("ActionName")',
        type: 'POST',
        contentType: 'application/json',
        data: JSON.stringify({ date: '..', person: '...' }),
        success: function(result) {           
        }
    });
    

    编辑:查看这个答案以获得完整的解决方案。
    jquery ajax forms for ASP.NET MVC 3

    【讨论】:

      猜你喜欢
      • 2013-01-12
      • 1970-01-01
      • 2018-03-26
      • 2016-06-04
      • 1970-01-01
      • 2017-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多