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