MVC Model Binding Not Working via AJAX request

前端 未结 1 622
无人及你
无人及你 2021-01-22 14:46

Having a little trouble with MVC model binding via AJAX.

Can someone tell me why the CreateTransfereeDetails property is not binding, it always comes back as \'null\'. <

1条回答
  •  北恋
    北恋 (楼主)
    2021-01-22 15:21

    use name attribute on input fields inside form. Name attribute's valuesare automatically assigned to model's properties.

    and use serialize() function of jquery to pass data using ajax

    function submit(){
        $.ajax({
            url: "/myurl",
            dataType: "json",
            traditional: true,
            type: "POST",
            data: $('#frm').serialize(),
            success: function (result) {
                //
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                //
            },
            complete: function () {
                //
            }
        });
    }
    

    0 讨论(0)
提交回复
热议问题