ASP.NET MVC: Display dynamic data on master pages

If you play with the MVC 2 bits for a while you will come to a very simple question: How can I display dynamic data on my master page?

The structur of an MVC App (this is my demo app) :


Each controller has it´s own View-Folder and render the specific view (EntryController route to Views\Entry\VIEW).

But if you try to add a dynamic control (a dynamic menu, news-ticker, overviews…) on a master page you have a problem: A master page has no real controller itself (maybe a master page could have a controller – but for this problem there is a very easy way to do this).

The CTP 2 includes a special controller – the "ComponentController":

I use the "ComponentController" in my demo app to display the whole category list and the tagcloud.

My "EntrySideBarController" inherit from "ComponentController"

    public class EntrySidebarController : ComponentController
        public void CategoryList()
            ... viewdata = ...
            RenderView("CategoryList", viewData);

        public void TagCloud()
            ... viewdata = ...
            RenderView("TagCloud", viewData);

The views "CategoryList" & "TagCloud" are located in a special folder (root\Components\CONTROLLERNAME\Views\VIEWNAME):


To render these components just use the "Html.RenderComponent" method (is similar to a usercontrol) :

    <%=Html.RenderComponent<EntrySidebarController>(component => component.CategoryList())%>
    <%=Html.RenderComponent<EntrySidebarController>(component => component.TagCloud())%>



For more information about the ComponentController, look at this post:

Using the ComponentController in ASP.NET MVC CTP 2

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

About the author

Written by

Currently there is no additional info about this author.

  • Harry

    RenderComponent seems gone in MVC Beta. Which method has been created to do the same?

  • Robert Muehsig

    The RenderComponent (or how it´s named in the actual version of ASP.NET MVC) is gone to the ASP.NET MVC Future – just link the future DLL.

Recent Posts

  • HowTo: make out Retweet-counter in a random URL

      Twitter offers some interesting functions with the integration of the twitter button – every user can see how often the website has been retweeted and he can do the same with just one click. But of course the whole thing has his price: - The integration of the Twitter JavaScript makes the whole data […]

  • Time-controlled Azure WebJobs – Azure as easy as it get‘s

        While still in development the Azure WebJob SDK offers some cool features for procession and supply of information. A good example is the sample that observes the Azure Queue and processes an item as soon as it spots one.   Scenario: time-controlled activities – without queue and so on My scenario was quite […]

  • image2021-570x194_thumb.png
    HowTo: Create RSS Feeds with ASP.NET MVC

    I’ve already written about how to consume RSS or Atom Feeds with the SyndicationFeed (in German, sry) but todays post is about how to create or publish an own feed. Beside the age of the feed standard and the much defamation from Facebook, Twitter and Google on RSS/Atom I consider this easy to consume API […]

  • image1997-311x194_thumb.png
    How to access an Azure Website with the local IIS Manager

    Since the end of February it is possible to access an Azure Website with the IIS Manager. Although the Azure Management site offers some information there are more details visible at the IIS Manager. For the connection you will need an IIS Manager and the IIS Manager for Remote Administration Extension. It’s also possible to […]

  • image1929-570x143_thumb.png
    Create and validate own Json-Web-Tokens (JWTs)

    If you are interested in web authentication you probably have heard about JSON Web tokens (JWT). What is a JWT? Maybe I’m not using the correct security termination but however: JWTs are used to exchange claims between two systems. For example: You want to log on to a service (like Facebook, Twitter, etc.) and want […]

Support us