Is there an alternative to get the route value in the view page instead of read it like querystring ?
@Html.ActionLink("Language Resources", "Index", "LanguageResource", new { languageCode = Request.QueryString["languageCode"] , "")
The route values are stored as string s, not int s, so we still need to convert them. We have routing but not model binding. GetRouteData() gives access to the whole RouteData object, so we can also access other data like data tokens. Alternatively, you can use GetRouteValue() to access a single route value at a time.
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. You can get the controller, action or parameter information using RouteData as shown below. Example: RouteData in MVC.
The ASP.NET Routing module is responsible for mapping incoming browser requests to particular MVC controller actions. By the end of this tutorial, you will understand how the standard route table maps requests to controller actions.
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. The RouteConfig. cs file is used to set routing for the application.
try to find from below code
In Razor
@{ var id = ViewContext.RouteData.Values["id"]; }
In WebForms:
<% var id = ViewContext.RouteData.Values["id"]; %>
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