【发布时间】:2016-03-21 20:12:40
【问题描述】:
我使用局部视图来呈现页面的内容。 通常,我使用部分来通过使用 @section
为内容呈现特定的脚本和 CSS我的基本网址是{Controller}/{Action}/{Id}
对于像{Controller}/{Action} 这样的网址,即。 Product/Create,部分和页面渲染正常。
但是当我的网址是{Controller}/{Action}/{Id} 时。 Product/Edit/2,没有 CSS 和脚本,我只得到一个纯 HTML 页面。
我的布局:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title</title>
<!-- CSS FILES -->
<link href="../assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css" rel="stylesheet" type="text/css" />
<!-- BEGIN RENDER CSS SECTION EXISTING IN PARTIAL -->
@RenderSection("Style", required: false)
<!-- END RENDER CSS SECTION EXISTING IN PARTIAL -->
<link href="../assets/global/css/components.min.css" rel="stylesheet" id="style_components" type="text/css" />
<link rel="shortcut icon" href="favicon.ico" />
</head>
<body>
<div class="header">
@Html.Partial("_Header")
</div>
<div class="container">
<div class="sidebar">
@Html.Partial("_Sidebar")
</div>
<div class="content">
@RenderBody()
</div>
</div>
<!-- JAVASCRIPT FILES -->
<script src="../assets/global/plugins/bootstrap-switch/js/bootstrap-switch.min.js" type="text/javascript"></script>
<!-- RENDER JAVASCRIPT SECTION EXISTING IN PARTIAL -->
@RenderSection("Scripts", required: false)
<!-- RENDER JAVASCRIPT SECTION EXISTING IN PARTIAL -->
<script src="../assets/layouts/layout/scripts/layout.min.js" type="text/javascript"></script>
</body>
</html>
我的部分视图结构:
@model IEnumerable<Backend.Models.Product>
@{
ViewBag.Title = "Product";
}
@section Style {
SPECIFIC CSS URLS TO THE VIEW
}
HTML CODE
@section Scripts{
SPECIFIC JAVASCRIPT URLS TO THE VIEW
}
我怀疑 URL 中的额外 {Id} 是什么弄乱了代码,因为以下内容:
{Id}
我该如何解决这个问题?
【问题讨论】:
-
这里没有足够的信息来开始。尝试提供一些代码来说明您的问题。
-
你是如何包含你的 css 的?你能显示代码吗?检查您的浏览器网络选项卡是否有 404 错误。这将使您了解它失败的原因
-
@ErikFunkenbusch 我编辑了我的帖子
-
@Shyju 我编辑了我的帖子
-
@Mikahel 查看我发布的答案。
标签: asp.net-mvc razor asp.net-mvc-partialview