ASP.NET MVC + AngularJS + PiranhaCMS + Foundation for Apps 路由问题
ASP.NET MVC + AngularJS + PiranhaCMS + Foundation for Apps routing issue
我处理这个问题的时间比我承认的要长。我已经阅读了我能找到的与我的问题非常相似的所有内容,并且空手而归。
我遇到的问题是让我的观点与 _Layout.cshtml 一起显示。当我启动网站时,正在加载 Index.cshtml 视图,但没有布局页面。
这里是_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>
我正在使用 UI 路由器和 AngularJS 来提供客户端,HTML5Mode 路由。这是我的 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);
}
})();
这里是/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>
这里是HomeController.cs
public class HomeController : SinglePageController
{
public ActionResult Index()
{
var model = GetModel();
return PartialView("~/Views/Home/Index.cshtml", model);
}
}
如果需要查看更多代码,请告诉我。
在/home/index.cshtml
中
您声明您希望布局为空。这实际上是说您不想使用此文件的布局。如果你有一个 _ViewStart.cshtml,它很可能默认指向 ~/Views/Shared/_Layout.cshtml。如果不是,你需要制作
Layout = "<path>/<to>/_Layout"
在 HomeController.cs 中,您正在返回 PartialView(...);主要用于 AJAX 和调用子视图。如果指定,它会忽略布局选项。你想使用
View(...);
我处理这个问题的时间比我承认的要长。我已经阅读了我能找到的与我的问题非常相似的所有内容,并且空手而归。
我遇到的问题是让我的观点与 _Layout.cshtml 一起显示。当我启动网站时,正在加载 Index.cshtml 视图,但没有布局页面。
这里是_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>
我正在使用 UI 路由器和 AngularJS 来提供客户端,HTML5Mode 路由。这是我的 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);
}
})();
这里是/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>
这里是HomeController.cs
public class HomeController : SinglePageController
{
public ActionResult Index()
{
var model = GetModel();
return PartialView("~/Views/Home/Index.cshtml", model);
}
}
如果需要查看更多代码,请告诉我。
在/home/index.cshtml
中您声明您希望布局为空。这实际上是说您不想使用此文件的布局。如果你有一个 _ViewStart.cshtml,它很可能默认指向 ~/Views/Shared/_Layout.cshtml。如果不是,你需要制作
Layout = "<path>/<to>/_Layout"
在 HomeController.cs 中,您正在返回 PartialView(...);主要用于 AJAX 和调用子视图。如果指定,它会忽略布局选项。你想使用
View(...);