1

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.

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

1 Comment

you always have solution to my problems. And pretty awesome solution
0

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

2 Comments

But this will affect all the views and not just single view
you should construct you layout in a more general way for layout view, if you need to have different layout simple using @layout ="url" so that you can render specific layout for certain view, if you want to change layout based on controller or others things you can set your logic in _ViewStart.cshtml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.