2

I am using the default Controller named "Home".

I have the following ActionResult:

public ActionResult SetID(string ID)
{
    int? result = MyGateway.GetAccountByID(ID);
    Common.IDNum = result;
    return View("Index","Home");
}

I would like to pass the IDNumber like:

http://localhost:3314/Home/SetID/AA3420

...and not like...

http://localhost:3314/Home/SetID?ID=AA3420

The link above is beginning generated by a view which returns a list. To select a record, they click "Select" which is the link above. I am currently setting the "AA3420" to a Session Variable located in a CS file elsewhere called Common.cs.

How can I get my URL to look like: http://localhost:3314/Home/SetID/AA3420?

tereško
  • 58,060
  • 25
  • 98
  • 150
Turp
  • 708
  • 3
  • 14
  • 26

2 Answers2

3

By Registering the following route in global.asax Application_Start:

 var routes = RouteTable.Routes;

 routes.MapRoute(
            "ID Action", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new {controller = "Home", action = "SetID", ID = ""} // Parameter defaults
            );
jenson-button-event
  • 18,101
  • 11
  • 89
  • 155
  • Thank you very much, BobTodd. That did the trick. I knew it had something to to with Routes, but wasn't sure how to do it correctly. I understand now. Much thanks your way. – Turp Dec 02 '11 at 15:53
0

Look in your Global.asax. There you define a default route and a default parameter. Like this:

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
arnistrong
  • 151
  • 3