Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you access the current RouteData from View in .net MVC?

If I want to directly access the RouteData (the current action or parameter values for example) from the View, rather than having to pass it in from the controller as part of the ViewData, what class would i use?

like image 964
Gene Reddick Avatar asked Jul 16 '09 00:07

Gene Reddick


People also ask

How do I navigate to another view in MVC?

You can use the RedirectToAction() method, then the action you redirect to can return a View. The easiest way to do this is: return RedirectToAction("Index", model); Then in your Index method, return the view you want.

How do I find my current controller?

Get controller name In preceding code, we use the ViewContext object to access the RouteData of the current request. After that, we use the Values property to access the current routing path values. By passing the controller key to the Values property we can get the current controller name.


1 Answers

this.ViewContext.RouteData 

should do the trick.

like image 120
womp Avatar answered Sep 22 '22 08:09

womp