控制器获取操作
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();
}