Asp.net mvc 4 httppost未能在模式引导中显示

Asp.net mvc 4 httppost未能在模式引导中显示,asp.net-mvc-4,twitter-bootstrap-3,http-post,Asp.net Mvc 4,Twitter Bootstrap 3,Http Post,我使用的是引导模式,我使用以下链接构建了模式: 一切正常,除了我调用[httppost]时,操作中出现了一些错误,如发布的电子邮件错误或不存在,然后我想在模式上显示错误。 而不是在模式上显示错误,而是在新页面中显示错误 _Layout.cshtml <div class="modal fade" id="log-in" tabindex="-1" aria-hidden="true" style="display: none;"> @Html.Action("Login","

我使用的是引导模式,我使用以下链接构建了模式:

一切正常,除了我调用[httppost]时,操作中出现了一些错误,如发布的电子邮件错误或不存在,然后我想在模式上显示错误。 而不是在模式上显示错误,而是在新页面中显示错误

_Layout.cshtml

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

如果您希望登录表单处于模式,则需要使用ajax发布表单,这样您就可以停留在同一页面上,并可以使用返回的错误消息或表单的部分视图更新DOM。我尝试过,但可能是我设置了错误可能是UpdatetargetidI尝试过了?试过什么?我们猜不出你做错了什么。@StephenMuecke:更新了ajax代码。。请检查并让我知道……谢谢
返回PartialView(“u Login”,model)
将您重定向到一个新页面,这意味着您没有在主视图(或布局)中包含
jquery.unobtrusive ajax.js
脚本
@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>
[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);
}