0
私はこのフォームがあります。ここではなぜ私のMVC 3フォーム投稿は、送信後にページをリフレッシュするのですか?
@using (Html.BeginForm("Update", "MyController", FormMethod.Post, new { id = "frmEdit" })) {
<input type="text" id="Title" value="Adam" />
}
はjQueryのです:
$(function() {
$('#frmEdit').submit(function() {
//read form values
//verify req fields
if (isValid) {
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
beforeSend: SpinWheel(l),
success: function (result) {
if (result.s == 'OK') {
alert("Success Updated");
}
else {
Alert("Sorry! Update failed.");
}
},
error: function (xhr, status, error) { alert('Error');}
});
}
return false;
});
});
コントローラー:
public ActionResult Update(FormCollection album)
{
return Json(new { s = "OK" });
}
フォームは内部のモーダルを持っています。親ページのリンクをクリックすると、モーダルが開始されます。 モーダルでは、送信ボタン付きフォームがあります。渡されたevent
にpreventDefault()
への呼び出しを追加
の終わりに
return false;
を打っていなかった理由である可能性があります。まだ他の問題を探しています。 – user943064