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

  • SEARCH
  • Home
  • 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 3594094
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:39:55+00:00 2026-05-18T19:39:55+00:00

We have a white-labelled platform built on Asp.Net MVC2. At present the site has

  • 0

We have a white-labelled platform built on Asp.Net MVC2. At present the site has 6 controllers, as well as all the core views etc that can enable it to work straight out of the box. So far we’ve built 5 sites from it and it’s all been great.

Now, however, I have a requirement that means I need to be able to pass a new piece of data (in the ViewData dictionary will be fine) to all views from any action. This data is seeded from query string and then from a cookie.

One of the primary reasons for this is to be able to add an extra image to the site’s master page depending on this data’s value. I could of course be really dirty and place the deserialization code in the master page; but I’d rather find a way to ensure that it gets added to the ViewData for every request that doesn’t involve controller inheritance and action method overriding(!).

Any ideas greatly greatly appreciated!

  • 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-18T19:39:56+00:00Added an answer on May 18, 2026 at 7:39 pm

    You could write a custom action filter attribute and apply this attribute to a base controller or all actions that need to have this information injected:

    public class AdditionalViewDataInjectorAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);
            filterContext.Controller.ViewData["foo"] = "bar";
        }
    }
    

    And then decorate your base controller with this attribute:

    [AdditionalViewDataInjector]
    public class BaseController: Controller { }
    

    In ASP.NET MVC 3 there’s a notion of global action filters so that you don’t even need to have a base controller or decorate all your actions with this filter. There’s a workaround allowing you to achieve the same in ASP.NET MVC 2. Now all your views get this additional property in the view data.

    This being said, the previous is an ugly workaround and not something I would recommend (ViewData is ugly). You may take a look at Html.Action and Html.RenderAction helpers. Here’s how this might look:

    public class MySpecialController: Controller
    {
        public ActionResult Index()
        {
            // Here you have access to the request, cookies, session, routes, ...
            var someModel = GetSomeModel();
            return View(someModel);
        }
    }
    

    Then have some strongly typed partial which will contain the required HTML (~/Views/MySpecial/Index.ascx) and finally include this in your master page:

    <%= Html.Action("index", "myspecial") %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div that has a one pixel solid white border on the
I have a VB.NET form with a red background and white text. I want
I have a white labelled application that is installed onto multiple customers' servers. On
I have this interface with multiple UILabels. On view loading i populate white labelled
I have a white page with only a 500x250 textbox and an image. The
I have a white container on top of the bg but it stops even
What does it mean when my servers have a white circle instead of a
I have a black-white tiff image with 15369x15360 pixels and 8 bit depth now
I have a table with white-space set to nowrap and columns widths restricted using
I have Textbox with blue Background and white Foreground . When entering a text

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.