Entering an identifier in <body> in ASP.NET MVC
I would like my views to be able to indicate the class for the tag <body>that is on my main page.
My first step was to do something like this:
<asp:Content ContentPlaceHolderID="BodyClassContent" runat="server">
view-item</asp:Content>
However, this will require this on the main page, which does not work:
<body class="<asp:ContentPlaceHolder ID="BodyClassContent" runat="server" />">
Any solutions for this?
+3
4 answers
I suggest a different approach.
You create a hierarchy of view models starting with MasterModel. When you instantiate the view object, you pass the body class to it.
public class MasterModel
{
string BodyCss { get; set; }
public MasterModel (string bodyCss)
{
BodyCss = bodyCss;
}
}
public class MyView1Model : MasterModel
: base ("body-view1")
{
}
Then in your main view, which should be strictly typed for MasterView:
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage<MasterModel>" %>
you just write:
<body class="<%= Model.BodyCss %>"></body>
+4
user151323
source
share