Pass Model To Controller using Jquery/Ajax

后端 未结 4 1408
执念已碎
执念已碎 2020-11-29 07:33

I am trying to pass my model to a controller using JQuery/Ajax, I\'m not sure how to do this correctly. So far I have tried using Url.Action but the model is

4条回答
  •  孤城傲影
    2020-11-29 08:03

    Use the following JS:

    $(document).ready(function () {
        $("#btnsubmit").click(function () {
    
                 $.ajax({
                     type: "POST",
                     url: '/Plan/PlanManage',     //your action
                     data: $('#PlanForm').serialize(),   //your form name.it takes all the values of model               
                     dataType: 'json',
                     success: function (result) {
                         console.log(result);
                     }
                 })
            return false;
        });
    });
    

    and the following code on your controller:

    [HttpPost]
    public string PlanManage(Plan objplan)  //model plan
    {
    }
    

提交回复
热议问题