views:

236

answers:

3

I am using .NET MVC, and within view pages I set a contentplaceholder that contains an ID to be used on the master page like so:

View page:

<asp:Content ID="CDomBodyId" ContentPlaceHolderID="DomBodyId" runat="server">LmpDemoRequests</asp:Content>

Master page:

<body id='<asp:ContentPlaceHolder ID="DomBodyId" runat="server"></asp:ContentPlaceHolder>'>

So in this particular case, the body tag would render like this on the final HTML page:

<body id='LmpDemoRequests'>

I would like to have double quotes around the body id tag, but inverting the quotes like the following makes intellisense unable to find the contentplaceholder, giving me a lot of warnings when I compile.

<body id="<asp:ContentPlaceHolder ID='DomBodyId' runat='server'></asp:ContentPlaceHolder>">

Is there any way around this?

+1  A: 

This is an issue with ASP.NET editor. It's not specific to MVC. I think the workaround is pretty good and I don't see a specific drawback.

Mehrdad Afshari
A: 

Not sure if I have misunderstood your question, but you can also add:

<body id="site" runat="server"></body>

And then access it on your page

HtmlControl body = (HtmlControl)Master.FindControl("site");
body.Attributes.Add("class", "LmpDemoRequests");

I hope I understood your correctly.

meep
Good suggestion, but am looking to keep the contentplaceholder
A: 

Try declaring BodyID as a property of your MasterPage. Set its value in the View pages. Then you can do something like <html> <body='<%= BodyID %>'> </body </html>

dr
I tried doing this before, but the problem i had was that the BodyId would be set by the child view page...so by the time the child view page gets rendered, its too late for the master page to read the value.
I just tested this and it worked for me. Did you set the property value in the Page_Load event of the View Page?
dr
Yeah you know what, I think i was trying to set the value within the content of the actual view page itself which I realize isnt correct...so I think your way might be the way to go.