ASP.NET MVC4 only showing @RenderBody content on IIS7
Setup: I’ve got a VM running Windows 7 upon which I’ve installed IIS7, MVC3 & MVC4 with Web Platform Installer. I’ve added a new website in IIS using a .NET 4.0 application pool, and then used the Visual Studio 2012 publish option to publish an MVC4 web app to the website’s root directory.
The problem is that the only output I am getting is whatever is in the individual views. There is no layout, nothing other than the @RenderBody content.
It works fine when I preview it with Visual Studio.
This is my _Layout.cshtml:
<!DOCTYPE html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
<link rel="shortcut icon" type="image/x-icon" href="~/favicon.ico">
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<!-- this is decorative -->
<div class="topbar"></div>
<div class="row header">
<div class="five columns logo">
<a href="@Url.Action("Index", "Home")">
<img src="@Url.Content("~/Content/images/logo.png")">
</a>
</div>
<div class="seven columns nav">
@Html.Partial("_TopNavigationPartial")
</div>
</div>
@RenderBody()
<div class="row">
<div class="twelve columns box-padding">
<div class="box">
<div class="row footer">
<div class="six columns copyright">© 2013 snip.</div>
<div class="six columns nav">
@Html.Partial("_BottomNavigationPartial")
</div>
</div>
</div>
</div>
</div>
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
</body>
</html>
All that will be output though is what is in the view, e.g:
<div class="row">
<div class="twelve columns box-padding">
<div class="box">
<h1>Home</h1>
<p>You are here: Home/Index</p>
</div>
</div>
</div>
Anyone have any idea why this might be so?
It’s probably just that I haven’t set up IIS7 right.
Edit: I just uploaded the Internet application and it has done the exact same thing. Only the view content is being output. So it’s definitely something in IIS.
Edit 2: I have set up an Internet application as an application in IIS but still it returns the view content only. Weird.
Edit 3: Got it working, not sure how. https://i.stack.imgur.com/8DCug.gif
Managed to fix this. Not sure exactly what was the problem, but I was making a new website and then dragging the published files into it, which wasn’t working.
I then added an application to the default website, which worked, but then I found this post which explained that the default website itself is an application.
So in the end I just copied the published files into the default root directory and it worked.