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
精彩评论