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!
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.
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.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With