c# - MVC 4 Razor _Layout.cshtml use a HTML section for only one page -


i have scenario want specific content _layout.cshtml used 1 view

"_layout.cshtml" looks this..

<div>     //common part pages - 1 </div>  <div>    //only index page - want index page.    //but don't know how specify condition. if(it index page) use section    //i can't move section index page,     //because have html content displayed on index page below section, i.e. common part-2. </div>  <div>     //common part pages - 2 </div>    @renderbody()   <div>      //common part pages - 3 </div> 

my index.cshtml page should this..

<div>     //common part pages - 1 </div>  <div>     //only index page </div>  <div>     //common part pages - 2 </div>    //content specific index.cshtml   <div>      //common part pages - 3 </div> 

and other pages should this..

<div>     //common part pages - 1 </div>  <div>     //common part pages - 2 </div>    //content specific other pages   <div>      //common part pages - 3 </div> 

how should it? should use?

you can make non mandatory section in master page

@rendersection("sectionforindex", required : false) 

and in index page implement it

@section sectionforindex { <div>     //only index page </div> } 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -