简体   繁体   English

没有从HTML Partial调用BeginForm

[英]BeginForm isn't getting called from HTML Partial

I need to make a table with a password reset modal in it and I have a div with the html partial for the reset password view in it. 我需要在其中创建一个带有密码重置模式的表,并且我有一个带有html部分的div,用于其中的重置密码视图。 Inside the partial it has a beginform that isn't ever getting called. 在局部中,它具有一个从未被调用过的beginform。 Also the manage method in the controller is never getting called either. 同样,控制器中的manage方法也不会被调用。 Any idea why? 知道为什么吗?

Could it be because of the fact I have a form outside the html partial too? 可能是因为我在html部分之外也有一个表格吗?

_ChangePasswordPartial.cshtml _ChangePasswordPartial.cshtml

@using Microsoft.AspNet.Identity
@model Spectrum.Models.ManageUserViewModel

@*<p>You're logged in as <strong>@User.Identity.GetUserName()</strong>.</p>*@

@using (Html.BeginForm("Manage", "User", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
    @Html.AntiForgeryToken()
    <h4>Change Password Form</h4>
    <hr />
    @Html.ValidationSummary()
    <div class="form-group">
        @Html.LabelFor(m => m.OldPassword, new { @class = "col-md-2 control-label" })
        <div class="col-md-10">
            @Html.PasswordFor(m => m.OldPassword, new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(m => m.NewPassword, new { @class = "col-md-2 control-label" })
        <div class="col-md-10">
            @Html.PasswordFor(m => m.NewPassword, new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" })
        <div class="col-md-10">
            @Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" })
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Change password" class="btn btn-primary" />
        </div>
    </div>
}

Index.html Index.html

<div class="modal fade" id="modalResetPassword" tabindex="-1" role="dialog">
    <div class="modal-dialog" style=" max-height:50%;  margin-top: 50px; margin-bottom:50px;">
        <div class="modal-content" style="max-height:50%">
            <form name="ResetPassword" role="form" data-ng-submit="formUser.$valid && vm.saveActiveUser()">
                <div class="modal-header btn-info">
                    <button type="button" class="close" data-close-modal data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title whitetext">Manage User {{vm.activeUser.UserName}}</h4>

                    <div class="modal-body" style="padding-left: 7px; padding-top: 0px; height: 550px;">
                        @Html.Partial("~/Areas/Administration/Views/Shared/_ChangePasswordPartial.cshtml")
                    </div>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

You are having nested forms ! 您正在嵌套表格 One in your index.cshtml and one in your partial view. 一个在您的index.cshtml ,另一个在您的局部视图中。 Nested forms are not valid ! 嵌套表格无效

Also i see you have some javascript/angular method for your outer form submit 我也看到你对外部表单提交有一些javascript / angular方法

Remove the outerform and everything will work fine (Assuming you do not have any javascript code which is intercepting the submit event and preventing the default form submit behavior. 删除外部形式,一切正常(假设您没有任何JavaScript代码可拦截Submit事件并阻止默认表单的提交行为。

<div class="modal fade" id="modalResetPassword" tabindex="-1" role="dialog">
    <div class="modal-dialog" style=" max-height:50%;  margin-top: 50px; margin-bottom:50px;">
        <div class="modal-content" style="max-height:50%">           
                <div class="modal-header btn-info">
                    <button type="button" class="close" data-close-modal data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title whitetext">Manage User {{vm.activeUser.UserName}}</h4>

                    <div class="modal-body" style="padding-left: 7px; padding-top: 0px; height: 550px;">
                        @Html.Partial("~/Areas/Administration/Views/Shared/_ChangePasswordPartial.cshtml")
                    </div>
                </div>            
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

Also make sure to use the correct action method name in your partial view's Html.BeginForm method call. 还要确保在局部视图的Html.BeginForm方法调用中使用正确的操作方法名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM