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 506831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:44:30+00:00 2026-05-13T06:44:30+00:00

All my controllers are based off of a BaseController, to share properties between them

  • 0

All my controllers are based off of a BaseController, to share properties between them and override OnActionExecuting to set some values based on the route.

I’m creating a BaseViewData class to do the same for all my view data.

At the moment I’m populating the view data like so (C#):

var viewData = new BaseViewData
{
    Name = "someName",
    Language = "aLanguage",
    Category = "aCategoryName"
};

I do this in every action that requires the view data. Some of the properties are common, need to be set throughout every action. Is there a way to set some of the properties on a more global scale?

If I instantiate the BaseViewData class in the OnActionExecuting method on the BaseController, how do I access the BaseViewData properties from the action in the regular controllers (derived from the BaseController)?

Update in response to Dennis Palmer:

I’m essentially doing this because of a nagging issue I’m having with ViewData[“lang”] not being populated randomly on some requests. ViewData[“lang”] contains “en” if the language is English, and “ja” if it is Japanese (well, it’s supposed to anyway). I populate ViewData[“lang”] inside OnActionExecuting on the BaseController.

In my view, I make a call to some partial views based on the language:

<% Html.RenderPartial(ViewData["lang"] + "/SiteMenu"); %>

But I’m randomly getting errors thrown that state “Cannot find /SiteMenu”, which points to the fact that ViewData[“lang”] has no value. I just cannot find any reason why ViewData[“lang”] would not get populated. So, I’m rewriting the site to use ONLY strongly typed view data (and setting some hard defaults). But if another method is better, I’ll go that way.

Thank you!

  • 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-13T06:44:30+00:00Added an answer on May 13, 2026 at 6:44 am

    I’m not sure I follow exactly what you’re trying to do, but if your view is using values in the route to display certain information, it seems like adding your own extension methods for HtmlHelper would be a better way to go.

    Are Name, Language and Category contained in your routes? If so, then HtmlHelper will have access to the route info and can determine what to display via the extension methods. What is the correlation between your routes and what your views need to know?

    Update: Is lang part of your route? If so, then I would still contend that you could write an HtmlHelper extension method that looks at the route data directly and determines which partial view to render. That way your controller wouldn’t even need to worry about setting the ViewData[“lang”]. The view would always know how to render based on the route.

    Update 2: I think dismissing use of an HtmlHelper extension method because it re-evaluates the route data might be a case of premature optimization. Your controller inheritance scheme sounds overly complex and you asked the question because the way you were setting ViewData was unreliable. I doubt that pulling the value from route data would be much, if any, less efficient than setting and reading from ViewData.

    From your comment:

    In the controller I use the lang value
    to determine which view to show as
    well.

    That only makes me think that there are more pieces of your system that I’d need to see in order to give better advice. If you have separate views for each language then why does the view need to be told which language to use?

    Another alternative to consider would be using nested master pages. You could have a single master page for your site layout and then a nested master page for each language that just contains a hard coded lang value.

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

Sidebar

Ask A Question

Stats

  • Questions 545k
  • Answers 545k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • added an answer Well, start off by thinking of which bits of data… May 17, 2026 at 9:17 am
  • added an answer For this task it is a good idea to use… May 17, 2026 at 9:15 am
  • added an answer This is exactly how the Skyhook database (built into many… May 17, 2026 at 9:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I've got some things I do in the OnActionExecuting method in a BaseController, that
In ASP.NET MVC, we're required to use the suffix Controller for all controllers. This
I'm developing webapp using spring 3 mvc and using annotation-based controllers. I want to
After freezing edge rails, all my controller examples are failing with MissingTemplate errors. e.g.,
What is the purpose of this Rails config setting... config.action_controller.consider_all_requests_local = true It's set
Situation: Site with content protected by username/password (not all controlled since they can be
I found several controlsets for that nice looking ribbons (DotNetBar, DivElements, ...), but all
All the articles I've found via google are either obsolete or contradict one another.
All the recent VisualSVN Server posts made me want to check it out. I
All front-end developers know the pain of coding for Firefox, then viewing our then

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.