Please let me explain the settings.
I have a Control Password Controller / Action and View. Here are the action signatures in my account controller:
public ActionResult ChangePassword(ChangePasswordMessageId? message)
[HttpPost]
public ActionResult ChangePassword(ChangePasswordViewModel model)
When the first change password is loaded, I have some data in the query string. Here is an example:
https://www.mywebsite.com/Account/ChangePassword?mobile=1
Here is the form declaration from the submission.
@using (Html.BeginForm("ChangePassword", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
The form is submitted with a simple submit button:
<div class="form-group">
<div class="col-md-offset-2 col-md-4">
<input type="submit" value="Change Password" class="btn btn-primary btn-block" />
</div>
</div>
The form has 3 fields: current password, new password and password confirmation. If the user correctly fills in all the data and passes all the checks on the client side, the form works fine. Everything works fine except for one use case.
, . HTTPPOST ChangePassword , . .
[HttpPost]
public ActionResult ChangePassword(ChangePasswordViewModel model)
{
if (ModelState.IsValid)
{
try
{
MembershipUser user = Membership.GetUser();
bool changePassword = user.ChangePassword(model.OldPassword, model.NewPassword);
if (changePassword)
{
string path = Url.Action("ChangePassword", new { Message = ChangePasswordMessageId.ChangePasswordSuccess });
temp = Request.UrlReferrer.ToString();
pos = temp.IndexOf("?");
if (pos > 0) path += "&" + temp.Substring(pos + 1);
return RedirectToLocal(path);
}
else
{
ModelState.AddModelError("", "Change Password failed.");
}
}
catch
{
ModelState.AddModelError("", "Change Password failed.");
}
}
return View(model);
}
, "return View (model)"; ?
. , .
!