Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 268
Ozzie Perez Avatar asked Sep 02 '10 13:09

Ozzie Perez


People also ask

What is URL routing in MVC?

In MVC, routing is a process of mapping the browser request to the controller action and return response back. Each MVC application has default routing for the default HomeController. We can set custom routing for newly created controller.

What is route value in MVC?

RouteData is a property of the base Controller class, so RouteData can be accessed in any controller. RouteData contains route information of a current request.


1 Answers

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();

like image 139
Ozzie Perez Avatar answered Sep 29 '22 05:09

Ozzie Perez