tags:

views:

57

answers:

1

In my MasterPages, I created a content place holder to insert a CSS file right after the ContentPlaceHolder for the title and before the one for the body.

However, when I create a new View, the CSS ContentPlaceHolder shows up after the body one instead of before.

How can I fix it so the CSS content place holder shows up in the correct order as in the master pages whenever I create a new View?

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
<asp:ContentPlaceHolder ID="Css" runat="server"></asp:ContentPlaceHolder>
<link rel="Stylesheet" href="../../Content/Site.css" />
<link rel="Stylesheet" href="../../Content/SiteMaster.css" />
</head>
<body>
<asp:ContentPlaceHolder id="MainContent" runat="server">
</asp:ContentPlaceHolder>
</body>
</html>
A: 

If you look at the Add View dialog box you will see, at the bottom, there is a field called ContentPlaceHolder ID. It appears whatever Content Placeholder Id is entered here will be rendered immediately after the Title content placeholder followed by all remaining placeholders so if you enter your css placeholder id in there you should get the behaviour you are expecting.
I have no idea why it works like this and would be interested to hear any suggestions.
Bizarrely if you enter TitleContent into this field then two placeholders are rendered on the view with that id!

Andy Rose
Thanks - that worked! I agree, that's really strange - I would have never been able to figure this out.
Castielle
This works so it makes it easier for developers to have their main placeholder (that will definitely have content) at the top of every view. It's easier to start writing/mainting code. And one more thing. Placeholder order in a view doesn't really matter. They can be completely reversed/mixed. They will display in the correct places as defined in a master page. So placeholder order in a view doesn't really matter.
Robert Koritnik
**Regarding the TitleContent placeholder**: I guess this is most certainly a bug. Title placeholder is just a placeholder. Putting it up first is another thing to make things easier for developers not to accidentally forget to enter view's title.
Robert Koritnik