我在Umbraco MVC 7中有一个应用程序,我有一个按钮,可以调用Modal弹出窗口来打开登录表单。这是放置在局部视图上的模态代码。
@inherits UmbracoTemplatePage
@using System.Web.Mvc.Html
@using ClientDependency.Core.Mvc
@using Umbraco.Web
@using Umbraco.Web.Models
@using Umbraco.Web.Controllers
@{
var loginModel = new LoginModel();
Html.EnableClientValidation();
Html.EnableUnobtrusiveJavaScript();
Html.RequiresJs("/umbraco_client/ui/jquery.js");
Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
}
@Html.RenderJsHere()
<div class="modal fade bs-example-modal-sm" id="login" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Login</h4>
</div>
@using (Html.BeginUmbracoForm<UmbLoginController>("HandleLogin", null, new { @class = "form-horizontal", role = "form" }))
{
<div class="modal-body">
<div class="form-group">
<div class="col-sm-12 formError">
@Html.ValidationSummary()
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
@Html.TextBoxFor(m => loginModel.Username, new { @class = "form-control", placeholder = "Username" })
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
@Html.PasswordFor(m => loginModel.Password, new { @class = "form-control", placeholder = "Password" })
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Login</button>
</div>
}
</div>
</div>
</div>
因此,当我没有输入任何内容并点击提交时,它会保持模态打开并显示验证错误,一切都很好,但是如果我键入错误的凭据,则关闭模态弹出窗口,而不是我想保持打开并显示返回的错误。我知道它没有提交,因为如果我尝试刷新浏览器,它会要求我重新发送表单。
有关我需要做些什么来修复它的任何建议?
非常感谢
答案 0 :(得分:3)
当没有验证错误时,表单会被提交,因此会发生页面重新加载,这就是模式弹出窗口关闭的原因。
解决方案: - 您需要使用AJAX提交登录表单,以便只提交页面的那一部分。