Cybercop
Cybercop

Reputation: 8678

MVC : Not render css class for certain view?

I am very new to css and don't have much knowledge about it.

I have a mvc application which uses a theme that is built based on bootstrap.

And in my _layout view I have this code

<div class="container body-content">
    @Html.Partial("_alerts")
    @RenderBody()       
    <hr />
    <footer>
        <p>&copy; @DateTime.Now.Year -myApp</p>
    </footer>
</div>

I'm guessing that all my view will be wrapped by container body-content class.

Which is fine, because my web app's content is not displayed in full width stretched.

But my home page(landing page) let's say. Has a slider and because of the container body-content class it is not being shown in full width.

This is how my home page starts

<div class="fullwidthbanner-container" style="overflow:visible">
    <div class="fullwidthbanner">
        <ul>
            <!-- Slide 1 -->
            <li data-transition="slideright">
   ...
   ...
   ...
</div>

and here is the class for fullwidthbanner-container

.fullwidthbanner-container {
    width: 100%!important;
    max-height: 550px!important;
    position: relative;
    padding: 0;
    overflow: hidden!important;
    margin:0px 0 0px;
}

How do I make my home page be not wrapped aroundcontainer body-content?

Please let me know if I have to provide more details.

Upvotes: 1

Views: 570

Answers (2)

card_master
card_master

Reputation: 418

Simply change the place you put the @RenderBody() and re-structure the layout page

for example you can do this

<body>
@RenderBody()

<div class="container body-content">
    @Html.Partial("_alerts")      
    <hr />
</div>

<footer>
    <p>&copy; @DateTime.Now.Year -myApp</p>
</footer>
</body>

By doing so you you view will not affect by the div with class container, body-content

Upvotes: 0

Andrei V
Andrei V

Reputation: 7476

You can try the following:

In your _Layout.cshtml add a code block before your HTML:

@{
     string classToSet = "";
     string action = ViewContext.RouteData.Values["action"] as String;
     string controller = ViewContext.RouteData.Values["controller"] as String;

     //you might need to check for nulls 
     if (!(action == "Index" && controller == "Home"))
     {
         classToSet = "container body-content";
     }
}

You can then set the class using Razor:

<div class="@classToSet">
     @Html.Partial("_alerts")
     @RenderBody()       
     <hr />
    <footer>
         <p>&copy; @DateTime.Now.Year -myApp</p>
    </footer>
</div>

Upvotes: 1

Related Questions