views:

201

answers:

2

I have an ASP.NET MVC application I'm building and I'm using a Master page. On this master page, I would like to further break things up by creating a separate file for "Tabs", "Header", and "Footer".

What kind of view should I create to encapsulate these things to help remove clutter from my Master Page? Also, how do I reference these in the correct place in my master view so I can have them rendered properly?

There are several different types of options available for creating views/content views/user controls, etc for MVC and I need to know which is the right one for this task and how to use it.

A: 

Have you already considered Usercontrols/Partial views ??

Edit:If its just html you can write html files and render using helper methods.

Perpetualcoder
Are they one in the same? Partial view isn't an option for me and I've read that people suggest not using User Controls. So, I'm really looking for more of an opinion.
KingNestor
From http://blog.wekeroad.com/blog/aspnet-mvc-using-usercontrols-usefully/ and http://bradwilson.typepad.com/blog/2008/08/partial-renderi.html. I think they are 95% if not 100% same
Perpetualcoder
Why aren't partial views an option here?
Wyatt Barnett
+3  A: 

If you are using WebForms Views then you have 3 options:

Partial Views / User Controls:

Using Html.RenderPartial (I think it is the best method for creating Tabs in ASP.NET MVC 1.0 for today). Your markup will be looking as:

<% Html.RenderPartial(ViewData["TabName"], ViewData["TabData"]); %>

Nested MasterPages:

  • Site.master with ContentPlaceHolders for Content, Header, Sidebars, Footer ...
  • Tabs.master with ContentPlaceHolder for Tabs in the <asp:Content ContentPlaceHolderID="Content" >
  • A lot of Tab1.aspx ... TabN.aspx for tabs .

HtmlHelper extensions:

You can use (I think it is wrong way for creating Tabs) something like this:

<% if(ViewData["TabName"] = "Tab1") { %>
    <%= Html.Tab1() %>
<% } else if(ViewData["TabName"] = "Tab2") { %>
    <%= Html.Tab2() %>
<% } else ...
... 
...
...
eu-ge-ne