Ajax form serialize doesnt bind when using multiple parameters in MVC Controller

前端 未结 2 1466
梦如初夏
梦如初夏 2021-01-06 05:44

I have a view with multiple inputs for my Model (Html.TextBoxFor(x => x.attribute) etc. And my ajax method is:

function callMethod() {
    $.ajax({
        t         


        
2条回答
  •  轮回少年
    2021-01-06 05:56

    Using .serialize() serializes your model as a query string (e.g. someProperty=someValue&anotherProperty=anotherValue&...). To add additional name/value pairs, you can append then manually, for example

    var data = $('#Form').serialize() + '&test=' + number;
    $.ajax({
        ....
        data: data;
    

    or use the param() method (useful if you have multiple items and/or arrays to add)

     var data = $("#Form").serialize() + '&' + $.param({ test: number }, true);
     $.ajax({
        ....
        data: data;
    

提交回复
热议问题