View To Action Mvc Route Values Are Null
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.
sharptooth2 Answers
maxlegomaxlegoView To Action Mvc Route Values Are Null Data
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: