View To Action Mvc Route Values Are Null

Posted on
View To Action Mvc Route Values Are Null Average ratng: 3,7/5 1674 reviews

I am using the following code to get the current 'action' in my view because I want to custom build an actionlink based on it.

Home / ASP.NET Forums / General ASP.NET / MVC / Passing Model Object in route values of. Passing Model Object in route values of Action link. View side im.

My end goal is to build some action links with Javascript, and the .js needs to know what the current controller and action is since I'd like it to be flexible. I found the above by browsing through the framework but I don't know if I've found the correct thing.

i.e.

Does anyone know if this is the easiest/most straightforward way to do this? Types of pointing devices.

sharptooth
123k70 gold badges424 silver badges846 bronze badges
Ben FinkelBen Finkel
2,6236 gold badges27 silver badges43 bronze badges
Values

2 Answers

View To Action Mvc Route Values Are NullmaxlegomaxlegoView To Action Mvc Route Values Are Null

View To Action Mvc Route Values Are Null Data

3,9613 gold badges25 silver badges40 bronze badges

You get route data from RequestContext, and it doesn't really matter how you get to that (there are multiple ways). I wouldn't worry about going through multiple objects (probably only takes a few microseconds). You can make the code nicer tho, either by creating an extension method (of url helper for example) or making the control in question inherit custom implementation of WebViewPage where you create a shortcut for what you need. Like that:

NecrosNecros

Not the answer you're looking for? Browse other questions tagged asp.net-mvc-3razor or ask your own question.