MVC 5 Ajax.Beginフォームに困惑しています。過去何度も問題なく使っていました。Ajax.BeginはMVC 5でページ全体を再提出しています
一般的な問題は、開発者がjquery.unobtrusive-ajax.jsファイルをインクルードすることを忘れているが、この場合ではないことです。
私はのAppSettingセクションでのWebConfigで有効:
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
私は3つのファイルが含まれています。
他のjsファイルが中断していないことを確認するために、レイアウトをnullに設定することさえできます。
<div id="contactSection">
</div>
@using (Ajax.BeginForm("SendContact", "Home", new AjaxOptions {UpdateTargetId = "contactSection" }))
{
<fieldset>
<div class="row">
<div class="form-group">
<div class="col-md-4">
<label >Full Name *</label>
@Html.TextBoxFor(m => m.contactVM.fullName, new { @class = "form-control", })
</div>
<div class="col-md-4">
<label >E-mail Address *</label>
@Html.TextBoxFor(m => m.contactVM.email, new { @class = "form-control", type = "email" })
</div>
<div class="col-md-4">
<label >Phone</label>
@Html.TextBoxFor(m => m.contactVM.phone, new { @class = "form-control" })
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-8">
<label >Subject *</label>
@Html.TextBoxFor(m => m.contactVM.subject, new { @class = "form-control" })
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-12">
<label >Message *</label>
@Html.TextAreaFor(m => m.contactVM.message, new { @class = "form-control", maxlength = "10000", rows = "8" })
</div>
</div>
</div>
</fieldset>
<div class="row">
<div class="col-md-12">
<input type="submit" class="btn btn-primary">
</div>
</div>
}
コントローラで
[HttpPost]
public PartialViewResult SendContact(MainVM vModel)
{
vModel.contactVM.success = true;
return PartialView("_ContactResults", vModel.contactVM);
}
、最終的には部分図
@if (Model.success)
{
<!-- Alert Success -->
<div id="alert_success" class="alert alert-success margin-bottom-30">
<button type="button" class="close" data-dismiss="alert" aria- hidden="false">×</button>
<strong>Thank You!</strong> Your message was successfully sent! As long it was not spam, we will get back to you asap.
</div><!-- /Alert Success -->
}
else
{
<!-- Alert Failed -->
<div id="alert_failed" class="alert alert-danger margin-bottom-30">
<button type="button" class="close" data-dismiss="alert" aria- hidden="false">×</button>
<strong>[SMTP] Error!</strong> Sorry something went wrong, try again please!
</div><!-- /Alert Failed -->
}
任意のアイデア?
あなたの要素は 'id =" contactSection "'でどこにありますか? –
文書の先頭です。 –
jsファイルが正しく読み込まれていますか? –