0

How I can pass an object of the model from view to controller using JS function?

<div class="col-md-offset-2 col-md-10">
            <button type="button" class="btn btn-secondary" onclick="BulkUpdate(@Model)">Bulk Update</button>
        </div>

 function BulkUpdate()
    {
        $('#myModal').modal('show');
    }

1 Answers1

0

Use ajax to hit your controller method. see the example:

JS

function BulkUpdate()
{
   var model = @Html.Raw(Json.Encode(youModel))
   $.ajax({
       type: 'post', //GET
       url: '@Url.Action("Send", "Home")',
       data: JSON.stringify({ contact: model }),
       contentType: 'application/json; charset=utf-8',
       dataType: "json",
       success: function (data) {
           alert(data);
       }
   });

}

Controller

public ActionResult Send(Send contact)
{
    //some code here
}
Ajay Kumar Oad
  • 560
  • 5
  • 15