I am follwing this dom-based routing for kicking off specific javascript on each page
http://viget.com/inspire/extending-paul-irishs-comprehensive-dom-ready-execution
So need to write a unique data attribute into the tag each time a page loads
e.g.
<body data-controller="Home" data-action="Index">
What’s the best place to put this logic for a razor view?
The body tag is in my masterpage (_layout.cshtml) file. And it needs to dynamically render that on each page
Was thinking of overriding OnActionExecuting in a base controller and have that inject the current controller and action name into the ViewBag. Then referencing the ViewBag properties in my _layout.cshtml
Does that make sense or is there a more appropriate place for this functionality?
You don’t need to pass the data through
ViewBag(although it could work), instead of you can access the current controller and action through theViewContextproperty in any View (even in Layout)For setting other “global properties” on the
ViewBagtheOnActionExecuting(maybe combined with a base class or using a custom a filter) is the right place.