get json data in controller action in asp.net mvc
I have asp.net mvc application. i want to configure the object in jquery and want to pass it to the the action of controller . where as in my script i am using this for configure data for the ajax call:
var arr=new Array();
arr.Push(0)=1;
arr.Push(1)=2;
arr.Push(2)=3;
var peform = {
EmpId: eId,
DepatrmentId:deptId,
EmpAddress:strAddress,
EmpBirthDate:bDate,
EmpAccountsId:arr
};
I am able to get the values in param here but. when I am trying this:
if(peform!=null)
{
var json = $.toJSON(peform);
$.ajax({
url: '/Load/SaveData',
type: 'POST',
dataType: 'json',
data: json,
contentType: 'application/json; charset=utf-8',
success: function (data) {
开发者_运维问答 }
});
}
it does not calls to action in controller. i think here :
var json = $.toJSON(peform);
is not working as expect. is it need to add any js file to reference ? or mistake in syntax? Or please suggest me any other remedy.
Try the following instead:
var json = JSON.stringify(peform);
精彩评论