Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a route value in the view (Asp.net Mvc)

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"] , "") 
like image 970
Daniel Ezra Avatar asked Jul 17 '13 11:07

Daniel Ezra


People also ask

How do you find a route value?

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.

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. You can get the controller, action or parameter information using RouteData as shown below. Example: RouteData in MVC.

How can use route in ASP.NET 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.

What is RouteConfig Cs in ASP.NET 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. The RouteConfig. cs file is used to set routing for the application.


1 Answers

try to find from below code

In Razor

@{     var id = ViewContext.RouteData.Values["id"];  } 

In WebForms:

<%      var id = ViewContext.RouteData.Values["id"]; %> 
like image 159
Amit Avatar answered Sep 19 '22 07:09

Amit