I have an URL:
/Account.aspx/Confirm/34a1418b-4ff3-4237-9c0b-9d0235909d76
and a form:
<% using (Html.BeginForm())
{ %>
<fieldset>
<p>
<label for="password" class="instructions">
Contraseña:</label>
<%= Html.Password("password") %>
<%= Html.ValidationMessage("password", "*") %>
</p>
<p>
<input type="submit" value="Validar" />
</p>
</fieldset>
<% } %>
In the controller’s action:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Confirm(string id, string password)
{
//code
}
I want to obtain the value of the GUID in the URL (the part after Confirm) and the value of the input password.
How can I do that?
EDIT:
I have registered this routes:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("Error.aspx/{*pathInfo}");
routes.IgnoreRoute("Admin/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}.aspx/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
routes.MapRoute("Root", "",
new { controller = "Home", action = "Index", id = "" });
}
I think anything is odd, but in the id parameter of the Confirm action I’m getting an empty string.
Isn’t this because you are POSTING your form that doesnt have the ID inside the form?
What you could do is on your Form page set the Model as the ID passed in then assign a hidden input value to this ID…
public ActionResult Confirm(string id) { return View(id); }Now the ViewData.Model will contain your ID. Put this inside your form.
Then when your form is submitted it will pass the ID through.
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Confirm(string id, string password) { //...now you have access to ID and password }