How to parse a string URL into MVC Route Values (area, controller, action, querystring)?

Ozzie Perez picture Ozzie Perez · Sep 2, 2010 · Viewed 14.6k times · Source

Is there a method to extract the area, controller, action, and querystring from a URL in ASP.NET MVC? Don't want to reinvent the wheel implementing my own if there's already a way to do it.

Thanks!

Answer

Ozzie Perez picture Ozzie Perez · Sep 2, 2010

I was able to get it from here:

String URL to RouteValueDictionary

To get the area from this example I used:

string area = routeData.DataTokens["area"].ToString();