DavidS
DavidS

Reputation: 2283

ASP.NET MVC 3 basic routing question

I am using ASP.NET MVC 3 and following the tutorial here http://www.asp.net/mvc/tutorials/asp-net-mvc-routing-overview-cs.

I am working on the sign up functionality and trying to make use of routing. So the typical scenario is:

  1. When the user wants to sign up, he would get taken to /Account/SignUp.
  2. Upon succesful sign up, he then gets redirected to /Account/SignUp/Successful.

I thought it would be simple enough but the "Successful" parameter never gets passed in the SignUp method in the controller.

 public ActionResult SignUp(string msg)
 {
     // Do some checks on whether msg is empty or not and then redirect to appropriate view
 }

In global.aspx.cs I've got pretty much the vanilla routing:

   routes.MapRoute(
            "Default",
            "{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional });

What am I failing to grasp here?

Upvotes: 0

Views: 592

Answers (2)

Andrew
Andrew

Reputation: 5430

Change the parameter from your method to id and create an get method for the /Account/SignUp action

public ActionResult SignUp()
{
  //this is the initial SignUp method
}

[HttpPost]
public ActionResult SignUp(string id)
{
  //User will be redirected to this method
}

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1039438

Your route parameter is called id, so:

public ActionResult SignUp(string id)
{
    ...
}

or change it to msg if you want:

"{controller}/{action}/{msg}"

Upvotes: 1

Related Questions