0
我有一个剃刀形式。这是表单的有用部分。对表单提交失败url正在改变
<div id="forgotBox" style="display:none;" class="col-xs-12 col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3 centerit">
<div class="col-md-12">
@using (Html.BeginForm("ForgotPassword", "Login", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.EditorFor(x => x.user, new { htmlAttributes = new { @class = "form-control", placeholder = "Email" } })<br />
@Html.ValidationMessageFor(x => x.user)
</div>
if (!String.IsNullOrWhiteSpace(ViewBag.ErrorMsg))
{
<div class="form-group field-validation-error">
@ViewBag.ErrorMsg
</div>
}
<div class="form-group">
<input type="submit" class="btn btn-primary" />
</div>
}
<div><a href="javascript:showLogin();">Login</a></div>
</div>
这里是它调用控制器方法:
[HttpPost]
public ActionResult ResetPassword(LoginViewModel vm)
{
ViewBag.ErrorMsg = "";
if (vm.confirmpass != vm.newPass)
{
//some error condition
ViewBag.ErrorMsg = "Passwords do not match.";
} else if (!String.IsNullOrWhiteSpace(vm.user)){
//code here for when you want to process when we have the userID
}
return View("ForgotPassword", vm);
}
}
}
的URL
当用户到达这个页面example.org/login?user=123
的return View("ForgotPassword", vm);
的URL更改后
example.org/login/ForgotPassword
我希望它保持example.org/login?user=123
,因为页面未成功提交并且正在使用URL参数。
你是在说我摆脱了'new {enctype =“multipart/form-data”})) ' – codeNinja
你为什么需要这个?当你想发送一个文件(文件上传)时你需要这个属性, – Shyju