I have a parameter I am passing in a url. When the user clicks the url they are taken to the site which allows them to enter additional information. (Password Reset) I need to take the token I pass as part of the url and put it in the model I submit to another controller which verifies the token and password and resets the password if verified. I can’t figure out how to get the passed parameter in the model.
My controller:
[AllowAnonymous]
public ActionResult TokenPasswordReset(string token)
{
return View();
}
My url I generate is
http://localhost:53272/Account/TokenPasswordReset?wzBXjkT1Y8qmWIECwSIFYQ2
In my view I try to set the hidden model value with.
<fieldset>
<legend>Reset Password Form</legend>
<ol>
<li>
@Html.LabelFor(m => m.NewPassword)
@Html.PasswordFor(m => m.NewPassword)
</li>
<li>
@Html.LabelFor(m => m.ConfirmPassword)
@Html.PasswordFor(m => m.ConfirmPassword)
</li>
</ol>
@Html.HiddenFor(model.UserToken = Request.Params["token"])
<input type="submit" value="TokenPasswordReset" />
</fieldset>
The password and confirm password are fine. I can’t figure out how to pull the token out of the url and get it into the model.UserToken. When I do this I get an error that says
The name ‘model’ does not exist in the current context
EDIT: When I change to Model as suggested below I get a new error. For some reason it does not pick up the Model in the HiddenFor.
Thanks to @Mystere Man and @MVCKarl. I was able to take components of their answers and solve my issue. MVCKarls solution seems like it would work, I just didn’t want to use ViewData. The URL I generate is this.
In my view I changed the hidden field to this.
This allowed me to submit it to my controller with only the model passed and I only need to validate the model.
Thanks again…