在按钮单击上依次显示模态状态错误

时间:2015-11-07 07:12:23

标签: c# asp.net-mvc-4 bootstrap-modal modelstate

Login

我一直试图在模态弹出窗口中一个接一个地显示模态状态错误但是在MVC中,一旦我们点击提交按钮就会显示模态错误,如上图所示。

我的问题是,我想一个接一个地显示此验证错误消息,当用户首次单击登录按钮时,它应该要求输入用户名,一旦用户填写UserName并单击提交,它应该要求输入密码。 这是我的代码:

    <div id="ModalLogin" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="dtModalLogin" aria-hidden="true">
       <div class="modal-dialog">
          <div class="modal-content">
             <div class="modal-header paddingTopBottom-5">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title text-center" id="ModalLogin">Validation Errors</h4>
             </div>
             <div class="modal-body alert-danger">
                <div class="row">
                   <div class="col-xs-2">
                      <i class="fa fa-warning fa-3x"></i>
                   </div>
               <div class="col-xs-10">
            <div>
         <h4> 
         @Html.ValidationSummary(false, "Please fill the Mandatory fields as shown below:")
         </h4>
      </div>
   </div>
   </div>
</div>
<div class="modal-footer">
   <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
   </div>
</div>
</div>
                </div>

我的视图设计:

@Html.TextBoxFor(Model => Model.Login.UserName, new { @placeholder = "UserName", @class = "form-control" })
            @Html.ValidationMessageFor(Model => Model.Login.UserName, "*")
            <br />
            @Html.PasswordFor(Model => Model.Login.Password, new { @placeholder = "Password", @class = "form-control" })
            @Html.ValidationMessageFor(Model => Model.Login.Password, "*")
            <br />
            <input id="btnLogin" type="submit" class="btn text-muted text-center btn-success" value="Sign in" data-toggle="modal" data-target="#ModalLogin" />

我的控制器方法:

[HttpPost]
    public ActionResult Login(ViewModel objView)
    {
if (ModelState.IsValid)
            {
//To do something
}
} 

0 个答案:

没有答案