How to send a model in jQuery $.ajax() post request to MVC controller method

前端 未结 7 1873
南方客
南方客 2020-11-27 02:47

In doing an auto-refresh using the following code, I assumed that when I do a post, the model will automatically sent to the controller:

$.ajax({
    url: \'         


        
7条回答
  •  旧时难觅i
    2020-11-27 03:16

    you can create a variable and send to ajax.

    var m = { "Value": @Model.Value }
    
    $.ajax({
        url: '<%=Url.Action("ModelPage")%>',
        type: "POST",
        data:  m,
        success: function(result) {
            $("div#updatePane").html(result);
        },
    
        complete: function() {
        $('form').onsubmit({ preventDefault: function() { } });
    
        }
    });
    

    All of model's field must bo ceated in m.

提交回复
热议问题