1

How can I pass model to jquery ajax my code id '@Model' is the model on the view.i need to pass this model to controller which accept argument of type login model.

 $('#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 doesn't work

Xordal
  • 1,369
  • 13
  • 29
Nitin Varpe
  • 10,450
  • 6
  • 36
  • 60

1 Answers1

6

For corrected post data you should serialize model

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

And form as:

@using ( @Html.BeginForm( "Login", "Customer", FormMethod.Post, new { id = "FormId" } ) )
{
    //Fields in view
    @Html.EditorFor(x=>x.Name)
    @Html.EditorFor(x=>x.Pass)
}
Xordal
  • 1,369
  • 13
  • 29