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

Related Questions

I am writing a query to fetch results for all the values in a
If all tables I want to delete from have the column gamer_id can i
I am trying to load a html page through UIWebview.I need to disable all
I am attempting to pull some information from my tnsnames file using regex. I
There doesn't seem to be any tried and true set of best practices to
If I write a python script using only python standard libraries, using Python 2.6
I have a new web app that is packaged as a WAR as part
I want to use a temp directory that will be unique to this build.
IE is giving me an undefined NAN when i try to view the calender...
My question is about memory use and objects in actionscript 2. If I have

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.