开发者

How to read Model values and send them by ajax post

I have the following code and it`s pointing out errors as follows

Error 1 The开发者_如何学C name 'date' does not exist in the current context

Error 2 The name 'person' does not exist in the current context

What is wrong?

 $("#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;
        });


Try this:

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

EDIT: Take a look at this answer for the complete solution.
jquery ajax forms for ASP.NET MVC 3

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜