httppost无法在模态引导程序中显示

时间:2015-10-04 09:32:51

标签: asp.net-mvc-4 twitter-bootstrap-3 http-post

我正在使用Bootstrap模式,我使用链接构建模态:http://codepen.io/elmahdim/details/azVNbN

一切正常,除非我调用[httppost]并且在发布的电子邮件错误或不存在等操作中出现错误,然后我想在模态上显示错误。 而不是在模板上显示错误,而是显示在破损的新页面中。

_Layout.cshtml

<div class="modal fade" id="log-in" tabindex="-1" aria-hidden="true" style="display: none;">
    @Html.Action("Login","User")
</div>

_Login.cshtml

@model FrontEnd.Models.LoginModel
@{
    var result = ViewBag.ResultModel;
}
@using Web.FrontEnd.Common

<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>   
        </div>


@using (Ajax.BeginForm("Login", "User", FormMethod.Post,
                    new AjaxOptions

                {

                    HttpMethod = "POST",
                    UpdateTargetId = "#log-in"// Modal id as mention in //_layout.cshtml

                }, new { @id = "loginUser", @class = "modal-form" }))
    {
            <div class="modal-body">
                @Html.AntiForgeryToken()
                @Html.ValidationSummary(true)
                @if (result.IsVisible)
                {
                    <div class="row">
                        <div class="col-md-12">
                            <div class="form-group">
                                @Html.Raw(@result.Message)
                            </div>
                        </div>
                    </div>
                }
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            @Html.TextBoxFor(model => model.Email, new { @class = "form-control", @placeholder = "Email", autocomplete = "off" })
                            @Html.ValidationMessageFor(model => model.Email)
                        </div>
                        <div class="form-group">
                            @Html.PasswordFor(model => model.Password, new { @class = "form-control", @placeholder = "Password", autocomplete = "off" })
                            @Html.ValidationMessageFor(model => model.Password)
                            <input type="hidden" name="LastPage" id="LastPage" value="@ViewBag.LastPage" />

                        </div>
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <div class="row">
                    <div class="col-md-12">

                        <button type="button" class="btn btn-info" data-toggle="modal" data-target="#google-login" data-dismiss="modal">< Back</button>
                        <button type="submit" class="btn btn-primary" value="Save">Log In</button>
                        <button type="button" class="linkButton" style="color: red" data-toggle="modal" data-target="#reset-password" data-dismiss="modal">Forgot Password?</button>
                    </div>
                </div>
            </div>
        }
    </div>
</div>

UserController.cs

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string LastPage)
{
    if (ModelState.IsValid)
    {
      // Code to add database
    }
    //something went wrong then show on modal?
    return this.PartialView("_Login",model);
}

0 个答案:

没有答案