asp.net mvc - MVC 4: Why is "_Layout.cshtml" not rendering on Home View? -


i'm new mvc development , have started new mvc 4 application build sort of personal portfolio practice. cannot figure out why _layout.cshtml not rendering within home or default view though. i've checked following:

  1. the app_start/routeconfig.cs file has not been modified since application created.
  2. the views/shared/_viewstart.cshtml has following (default):

    @{     layout = "~/views/shared/_layout.cshtml"; } 

views/shared/_layout.cshtml:

        <!doctype html>     <html>         <head>             <meta charset="utf-8" />             <meta name="viewport" content="width=device-width, initial-scale = 1.0" />             <title>portfolio</title>             @styles.render("~/content/css")             @scripts.render("~/bundles/jquery")             @scripts.render("~/bundles/bootstrapjs")             @scripts.render("~/bundles/customjs")             <link href="~/content/bootstrap.css" rel="stylesheet" />             <link href="~/content/bootstrapmod.css" rel="stylesheet" />             <link href="~/content/site.css" rel="stylesheet" />         </head>         <body style=""zoom: 1">             <div class="container maincontent">                 <div class="page-header hidden-sm hidden-xs">                     @html.partial("_header")                 </div>                  <nav id="navbar" class="navbar navbar-default" role="navigation">                     <div class="container-fluid">                         <!-- brand , toggle grouped better mobile display -->                         <div class="navbar-header">                             <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse">                                 &#9776;                             </button>                             <a class="navbar-brand hidden-lg hidden-md" href="/home">portfolio</a>                         </div>                          <!-- collect nav links, forms, , other content toggling -->                         <div class="collapse navbar-collapse" id="navbar-collapse">                                                @*@html.mvcsitemap().menu()*@                          </div>                     </div>                 </nav>                  <div class="container">                     @rendersection("scripts", required:false)                      <div class="pagetitle largefontsize">                         @viewbag.headertitle                     </div>                      @renderbody()                 </div>               </div>             <div id="footer">                 copyright 2014 - portfolio - <a target="_blank" href="/terms-and-conditions-of-us.html">website terms &amp; conditions of use</a>             </div>         </body>     </html> 

~/views/shared/_header.cshtml

<div class="row">     <div class="col-md-6">         <div>             <a href="~/home">                 <img src="~/content/images/header.png" class="img-responsive"/>             </a>         </div>     </div>     <div class="col-md-6 box">         @if (request.isauthenticated)         {             <div class="profilelinks">                                     <a href="#">my projects</a>                 |                 <a href="#">contact profile</a>             </div>              <div class="content logout">                                 <div class="row">                     <div>                         hi, @user.identity.name                         @html.actionlink("log off", "logoff", "account", new {},new { @class = "btn btn-primary btn-sm" })                     </div>                 </div>                             </div>         }         else         {             <div class="content">                 <div class="row">                     <div class="col-md-4">                         <input type="text" id="username" placeholder="e-mail" required tabindex="1"/>                         <a href="#" ><h6>forgot username?</h6></a>                     </div>                     <div class="col-md-4">                         <input type="password" id="password" placeholder="password" required tabindex="2" onkeyup="enterkeypressed()"/>                         <a href="#" ><h6>forgot password?</h6></a>                     </div>                     <div class="col-md-4">                         <input type="button" id="loginbutton" value="login" onclick="login()" class="btn btn-primary btn-sm" tabindex="3" onkeyup="enterkeypressed()"/>                         <br />                         <input type="checkbox" id="rememberme">remember me                     </div>                 </div>             </div>         }     </div> </div> 

my default view below loads, nothing present. title changes "index", , rest blank page. shouldn't ~/views/shared/_layout.cshtml rendering within page in manner?

with have set-up, when shared _layout.cshtml loads within home/index/ view, should see header image have created , sourced on shared view.

views/home/indx.cshtml

@{     layout = null; }  <!doctype html>  <html> <head>     <meta name="viewport" content="width=device-width" />     <title>index</title> </head> <body>     <div>      </div> </body> </html> 

when try layout = "~/views/shared/_layout.chtml"; errors out saying not found @ designated path. semi-working off example developer friend sent me, , not explicitly setting layout?

couple of things...

if have view trying render in shared view not need of html layout elements contained within view putting into. lets start basic.

view start

@{     layout = "~/views/shared/_layout.cshtml"; } 

_layout.cshtml

<!doctype html> <html>     <head>         <meta charset="utf-8" />         <meta name="viewport" content="width=device-width" />         <title>@viewbag.title</title> </head> <body>     @renderbody() </body> </html> 

home view

@{     viewbag.title = "index"; }  <h2>index</h2> 

now home view gets plonked @renderbody() appears. index heading 2 in page. title passed in viewbag object , set page title in _layout.cshtml file following @viewbag.title


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -