Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7663969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:11:01+00:00 2026-05-31T14:11:01+00:00

I am follwing this dom-based routing for kicking off specific javascript on each page

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:11:03+00:00Added an answer on May 31, 2026 at 2:11 pm

    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 the ViewContext property in any View (even in Layout)

    <body 
       data-controller="@(ViewContext.RequestContext.RouteData.Values["controller"])" 
       data-action="@(ViewContext.RequestContext.RouteData.Values["action"])">
    

    For setting other “global properties” on the ViewBag the OnActionExecuting (maybe combined with a base class or using a custom a filter) is the right place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm implementing Comet using the script tag long polling technique, based on this page
I'm building an web app that uses this code to search for addresses: http://code.google.com/intl/en/apis/maps/documentation/javascript/examples/places-autocomplete.html
This seems possible as http://www.knockoutjs.com appears to be doing it. I haven't been able
This is a Continuation of Jeditable: how to set parameters based on dom element
Following this tutorial (http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/handling-concurrency-with-the-entity-framework-in-an-asp-net-mvc-application), I learned how to save data and do concurrency checks
I'm following this guide: http://www.math.umd.edu/~dcarrera/ruby/0.3/chp_01/programs.html and I'm trying to create my first ruby program.
I have been trying to implement 2 Seperate Contact Modals based off an original
--- Following on from what people have said --- This is for a multi-page
My research into the base HTML DOM element says this about any DOM element's
I have a YUI menu top bar navigation menu based from this example .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.