I have been working on this issue for longer than I'd like to admit. I have read everything I could find closely resembling my issue, and have come up empty handed.
The problem I am having is getting my views to show WITH _Layout.cshtml. When I fire up the site, the Index.cshtml view is being loaded, but without the layout page.
Here is _Layout.cshtml:
<!DOCTYPE html>
<html lang="en" ng-app="retail">
<head>
<title>@ViewBag.Title</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
@UI.Head()
<link type="text/css" rel="stylesheet" href="../../Content/Css/style.css"/>
@RenderSection("head", required: false)
</head>
<body>
<!-- This is the off-canvas menu that will slide in from the left !-->
<zf-offcanvas id="OffCanvasMainMenu" position="left">
<div id="MainMenu">
<div class="menuBlock">
<span class="spacer"></span>
<ul>
<li><a href="#">Menu Item</a></li>
<li><a href="#">Menu Item</a></li>
<li><a href="#">Menu Item</a></li>
</ul>
</div>
</div>
</zf-offcanvas>
<div class="grid-frame vertical">
<div id="Header" class="shrink collapse grid-content">
<div class="dark title-bar">
<span class="title center">
<img class="logo" src="logo.png">
</span>
<span class="left">
<button zf-toggle="OffCanvasMainMenu" id="MainMenuToggle">
<span>toggle menu</span>
</button>
</span>
<span class="right"><a id="c-button--slide-right" class="c-button dark"><i
class="fa fa-shopping-cart fa-2x" aria-hidden="true"></i></a></span>
</div>
</div>
<div class="grid-block">
<ui-view>
</ui-view>
</div>
</div>
<!-- This is the Shopping Cart that will slide over from the right !-->
<nav id="c-menu--slide-right" class="c-menu c-menu--slide-right">
<button class="c-menu__close">Close Menu →</button>
</nav><!-- /c-menu slide-right -->
@Scripts.Render("~/bundles/jquery")
<script src="../../lib/angular-touch/angular-touch.js"></script>
<script src="../../lib/ui-bootstrap-custom/ui-bootstrap-custom-tpls-1.3.3.js"></script>
<script src="../../Scripts/build/foundation.js" type="text/javascript"></script>
<script src="../../Scripts/build/templates.js" type="text/javascript"></script>
<script src="../../Scripts/app/core/core.module.js"></script>
<script src="https://use.fontawesome.com/154af4e77a.js"></script>
<script src="../../Scripts/app/home/HomeController.js"></script>
<script src="../../Scripts/assets/menu.js"></script>
</body>
@RenderSection("script", required: false)
</html>
I am using UI Router with AngularJS to provide client-side, HTML5Mode routing. Here is my app.js:
(function() {
'use strict';
angular.module('retail', [
'retail.core'
])
.config(config)
.run(run);
config.$inject = ["$stateProvider", "$urlRouterProvider", "$locationProvider"];
function config($stateProvider, $urlProvider, $locationProvider) {
$urlProvider.otherwise("/");
$stateProvider
.state("home", {
url: "/",
templateUrl: "/Home/Index",
controller: "HomeController",
controllerAs: "home"
});
$locationProvider.html5Mode({
enabled: false,
requireBase: false
});
$locationProvider.hashPrefix('!');
}
function run() {
FastClick.attach(document.body);
}
})();
Here is /Home/Index/cshtml:
@model Piranha.Models.PageModel
@{
Layout = null;
}
<div class="content">
<div class="main">
<h1>@Model.Page.Title</h1>
@Model.Regions.Ad
</div>
<div>
@Model.Regions.CampaignHeader
</div>
<div>
@Model.Regions.CampaignProduct1
</div>
<div>
@Model.Regions.CampaignProduct2
</div>
<div>
@Model.Regions.CampaignProduct3
</div>
<div>
@Model.Regions.CampaignProduct4
</div>
</div>
Here is HomeController.cs
public class HomeController : SinglePageController
{
public ActionResult Index()
{
var model = GetModel();
return PartialView("~/Views/Home/Index.cshtml", model);
}
}
If there is any further code that needs to be seen, please let me know.
In /home/index.cshtml
You state that you want the Layout to be null. This literally says that you don't want a layout used with this file. If you have a _ViewStart.cshtml it most likely will be pointing to ~/Views/Shared/_Layout.cshtml by default. If not you need to make
Layout = "<path>/<to>/_Layout"
In HomeController.cs, you are returning PartialView(...); which is primarially used for AJAX and for calling Sub-Views. It ignores the layout options if specified. You want to use
View(...);