コントローラ取得アクション
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();
}