开发者

How to read Model values and send them by ajax post

开发者 https://www.devze.com 2023-02-11 19:34 出处:网络
I have the following code and it`s pointing out errors as follows Error 1The开发者_如何学C name \'date\' does not exist in the current context

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

精彩评论

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

关注公众号