Pass model to controller from jquery ajax

How to pass a jquery ajax model my code identifier '@Model' is a model on view.i you need to pass this model to a controller that takes an argument of an input model of type.

$('#reject1').click( function() { var model=@Model ; $.ajax({ cache:true, type: "POST", url: "@(Url.Action("Login", "Customer"))", data:'model='+model, success: function() { //Some logic }, complete : function() {} }); return false; }); 

Above code does not work

+1
jquery asp.net-mvc-3 razor
source share
1 answer

For corrected post data you must serialize the model

 data: $('#FormId').serialize() 

And form like:

 @using ( @Html.BeginForm( "Login", "Customer", FormMethod.Post, new { id = "FormId" } ) ) { //Fields in view @Html.EditorFor(x=>x.Name) @Html.EditorFor(x=>x.Pass) } 
+6
source share

All Articles