jQuery的可以做一个视图模型的POST在ASP.NET MVC控制器? [英] Can jQuery do a POST of a ViewModel to a Controller in ASP.NET MVC?

查看:122
本文介绍了jQuery的可以做一个视图模型的POST在ASP.NET MVC控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的HTML文本框创建,以便回发到服务器时,它们将被绑定到自定义视图模型。

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("CustomerFormViewModel.Email")%>

这个伟大的工程,如果它是一个传统的POST。然后我可以接受它的控制器侧是这样的:

This works great if it's a traditional POST. I can then receive it on the Controller side with something like this:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult AddCustomer(CustomersFormViewModel model)
{
     //validate data, save customer, handle validation errors...
}

我想知道 - ?是否有可能通过jQuery做自检,仍然得到同样的行为

I want to know -- is it possible to do the POST via jQuery and still get the same behavior?

推荐答案

这是可能的,有一个传统POST和AJAX邮报没有什么区别。例如:

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) {
    }
});

这篇关于jQuery的可以做一个视图模型的POST在ASP.NET MVC控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆