How can I set the <body> class based on the view in Asp.Net MVC? -


Body & gt; Based on the view of the class as well

I'm looking to set & lt Am

I have read something about hard writing some pages, but nobody seems to be feeling well, or at least I do not know how to code < P> I have seen that stack overflow does this, so it should be possible.

Renewed:

Getting the Error: Description: An error occurred while compiling the resources needed to fulfill this request. . Please review the following specific error details and modify your source code appropriately

compiler error message:. CS1061: does not include a definition for 'System.Web.Mvc.HtmlHelper' 'body' and no extension method 'Body System.Web.Mvc.HtmlHelper' can be found to accept a first type of 'type' Code> body (if you are using an instruction or missing an assembly reference?) line

  namespace MySite.Helpers {public static Class HtmlHelpers {public static MvcHtmlString body (this HtmlHelper HtmlHelper) {string currentControllerName = (string) htmlHelper.ViewContext.RouteData.Values ​​["controller"]; String currentAction name = (string) htmlHelper.ViewContext.RouteData.Values ​​["action"]; String css = currentControllerName + "-" + current operationname; Var body = new tag builder ("body"); Body.AddCssClass (CSS); Return MvcHtmlString.Create (body.ToString (TagRenderMode.StartTag)); }}}  

~ / visual / share / Site.Master:

   & Lt ;! DOCTYPE HTML PUBLIC "- // W3C // DTD XHTML 1.0 Stronger // N" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> & Lt; Html xmlns = "http://www.w3.org/1999/xhtml" & gt; & Lt; Head runat = "server" & gt; & Lt; Title & gt; & Lt; Asp: ContentPlaceHolder ID = "TitleContent" runat = "server" /> & Lt; / Heading & gt; & Lt; Link href = "../../content / site.css" rel = "stylesheet" type = "text / css" /> & Lt; / Head & gt; & Lt; Body id = "argh" class = "& lt;% = Html.Body ()% & gt; & Gt;  

You can use a helpful method:

  Public static MvcHtmlString body (this HtmlHelper HtmlHelper) {string currentControllerName = (string) helper.ViewContext.RouteData.Values ​​["controller"]; String current Actions name = (string) assistant. Visual Restore Root data Value ["action"]; String CSS = GetCss (current controller name, current Actions); Var body = new tag builder ("body"); Body.AddCssClass (CSS); Return MvcHtmlString.Create (body.ToString (TagRenderMode.StartTag)); }  

and then in your master page:

  <% = Html.Body ()%> ... & lt; / Body & gt;  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -