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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:35:19+00:00 2026-05-11T15:35:19+00:00

What is your way of passing data to Master Page (using ASP.NET MVC) without

  • 0

What is your way of passing data to Master Page (using ASP.NET MVC) without breaking MVC rules?

Personally, I prefer to code abstract controller (base controller) or base class which is passed to all views.

  • 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. 2026-05-11T15:35:19+00:00Added an answer on May 11, 2026 at 3:35 pm

    If you prefer your views to have strongly typed view data classes this might work for you. Other solutions are probably more correct but this is a nice balance between design and practicality IMHO.

    The master page takes a strongly typed view data class containing only information relevant to it:

    public class MasterViewData {     public ICollection<string> Navigation { get; set; } } 

    Each view using that master page takes a strongly typed view data class containing its information and deriving from the master pages view data:

    public class IndexViewData : MasterViewData {     public string Name { get; set; }     public float Price { get; set; } } 

    Since I don’t want individual controllers to know anything about putting together the master pages data I encapsulate that logic into a factory which is passed to each controller:

    public interface IViewDataFactory {     T Create<T>()         where T : MasterViewData, new() }  public class ProductController : Controller {     public ProductController(IViewDataFactory viewDataFactory)     ...      public ActionResult Index()     {         var viewData = viewDataFactory.Create<ProductViewData>();          viewData.Name = 'My product';         viewData.Price = 9.95;          return View('Index', viewData);     } } 

    Inheritance matches the master to view relationship well but when it comes to rendering partials / user controls I will compose their view data into the pages view data, e.g.

    public class IndexViewData : MasterViewData {     public string Name { get; set; }     public float Price { get; set; }     public SubViewData SubViewData { get; set; } }  <% Html.RenderPartial('Sub', Model.SubViewData); %> 

    This is example code only and is not intended to compile as is. Designed for ASP.Net MVC 1.0.

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

Sidebar

Related Questions

For example, your application is using this way for passing vars into your application
What is the best way of showing your ExtJs app after a page refresh?
Can you share the way you setup your unit test projects within your .net
Is there a way to figure out if the tab your web page is
Link I'm using ASP.NET with C# and trying to use linq to sql to
I need your help in finding better way in downloading a url using HttpWebResponse
In asp.net mvc, I have been thinking it would be more advantageous to specify
Is there a (or, do you have your own) preferred way to do background
Is there a way to detect if your program was loaded through Visual Studio
Is there a way to automatically set what your remotes are on a git

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.