我需要在其中创建一个带有密码重置模式的表,并且我有一个带有html部分的div,用于重置密码视图。在局部内部,它有一个不会被调用的开始形式。控制器中的管理方法也永远不会被调用。知道为什么吗?
可能是因为我在html partial之外还有一个表格吗?
_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
<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">×</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 -->
答案 0 :(得分:1)
您正在使用嵌套表单!一个在index.cshtml
中,一个在您的局部视图中。 Nested forms are not valid!
此外,我发现你的外表提交有一些javascript / angular方法
删除外形并且一切都会正常工作(假设您没有任何javascript代码拦截提交事件并阻止默认表单提交行为。
<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">×</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 -->
还要确保在部分视图的Html.BeginForm
方法调用中使用正确的操作方法名称。