我有我的AJAX电话
$.ajax({
type: 'post',
url: "/Store/LoadStoreIndex",
data: , //Entire Model Here!!
dataType: "text",
success: function (result) {
$('#Postback').html(result);
}
});
我需要将整个模型发送回控制器,但经过多次搜索后找不到任何东西......有人能告诉我我需要做什么吗?
答案 0 :(得分:4)
控制器获取行动
public ActionResult Index(YourModel model)
{
YourModel model = new YourModel();
return View(model);
}
查看
@model YourModel
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "form1" }))
{
@Html.TextBoxFor(x => x.EmailAddress)
@Html.TextBoxFor(x => x.Name)
...
}
脚本
$(function () {
$('form').submit(function () {
if ($(this).valid()) {
$.ajax({
url: this.action,
type: this.method,
// you can post your model with this line
data: $(this).serialize(),
beforeSend: function () {
},
complete: function () {
},
success: function (result) {
},
error: function () {
}
});
}
return false;
});
});
控制器发布操作
[HttpPost]
public ActionResult Index(YourModel model)
{
return View();
}