Can jQuery do a POST of a ViewModel to a Controller in ASP.NET MVC?

后端 未结 2 834
时光说笑
时光说笑 2020-12-31 15:45

I have my Html Textboxes created so that they will be bound to a custom view model when posting back to the server.

<%= Html.TextBox(\"CustomerFormViewMod         


        
相关标签:
2条回答
  • 2020-12-31 16:12

    It is possible, there is no difference between a "traditional POST" and "AJAX Post". For example:

    $.ajax({ type: "POST",
        url: '<%= Url.Action("AddCustomer", "Customer") %>',
        data: $('form').serialize(),
        success: function(data, textStatus) {
        }
    });
    
    0 讨论(0)
  • 2020-12-31 16:24

    If I understand you right, I think it's pretty simple

    var formData = $("#form").serialize();
    
    $.post("path/to/action", formData, function(data) { //success } );
    
    0 讨论(0)
提交回复
热议问题