tags:

views:

418

answers:

3

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.

A: 

In your Global.asax.cs, define a route for Confirm that specifies the last part of the URL is a parameter.

Eg:

"Account/Confirm/{id}"

The MVC framework will automatically parse the URL and return the GUID in the id parameter

Jon Benedicto
A: 

You didn't really indicate what URL is getting posted back to, just the one that is for the form, but try this:

var pathInfo = HttpContext.Request.PathInfo

This should return /Confirm/34a1418b-4ff3-4237-9c0b-9d0235909d76, you probably can make this easier if you have a Route associated with this page, by just naming the GUID to a RouteValue. If you have a route post it and I will be glad to help.

Nick Berardi
I assign the GUID to the id parameter of the route collection, but I don't get the value of the GUID in the id action parameter in the form post.
eKek0
Have you used Fiddler to see what the URL that is being POSTed back to.
Nick Berardi
+1  A: 

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...

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
Inherits="System.Web.Mvc.ViewPage<string>" %>
public ActionResult Confirm(string id)
{
   return View(id);
}

Now the ViewData.Model will contain your ID. Put this inside your form.

<input type="hidden" id="id" name="id" value="<%= ViewData.Model %>" />

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
}
David Liddle