简体   繁体   中英

Layout in _layout.cshtml in ASP.NET MVC

I want to have a layout having three container: left container , central container and right container in the _layout page.I tried with the following code but it dosen't respond with the expected result.

<body>
        <header>
            @Html.Partial("_header")
        </header>       

         <div class="row">

             <div class="col-lg-4 well">
                 hello there lcont
                 @RenderBody()
             </div>

             <div class="col-lg-4 well" >
                  Central container
             </div>

             <div class="col-lg-4 well ">
                 right container
             </div>


         </div>



        <footer>
            <div class="content-wrapper">
                <div class="float-left">
                    <p>&copy; @DateTime.Now.Year - My ASP.NET MVC Application</p>
                </div>
            </div>
        </footer>

        @Scripts.Render("~/bundles/jquery")
        @RenderSection("scripts", required: false)
    </body>

Instead of getting three divs side by side in a single row i get three different rows.

在此处输入图片说明

EDIT

I changed col-lg-4 to col-md-4 and it worked as it is suposed to.Any explanation i am confused.

You'll need to use section s and RenderSection() instead of RenderBody() .

In your _Layout.cshtml , render the sections like this,

<div class="row">

    <div class="col-lg-4 well">
        hello there lcont
        @RenderSection("Left")
    </div>

    <div class="lg-col-4 well">
        @RenderSection("Center")
    </div>

    <div class="lg-col-4 well ">
        @RenderSection("Right")
    </div>


</div>

And in each content.cshtml page, divide the section contents like this:

@section Left{
   <span> left content goes here</span> and here
}

@section Center{
   <div> Center content </div>
}

@section Right{
  any html here goes to <aside> Right content </aside>
}

NOTE: If your problem is that div s are coming below each other, make sure you include the bootstrap or relevant css that provide grid system as I see from your use of col-lg-* classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM