Question

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?

Was it helpful?

Solution

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>

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top