James Ray Anderson

James Ray Anderson
James Ray Anderson
0 comments

MVC - Get Route Data

9:00 PM
Here is another way to get the Route Data.  This is useful when calling another Action on Another controller and passing values.

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

Controller:
public ActionResult Index(int id)
{
          int val2 = id;
          int val1 = Routedata.Values["id"];
}

0 comments:

 
Toggle Footer
Top