首页 新闻 会员 周边

当使用PartialView()返回的视图时,<environment>不启作用

0
悬赏园豆:50 [已解决问题] 解决于 2017-03-30 12:58

Action中使用PartialView()返回视图,视图代码如下

<!DOCTYPE html>
<html>
<head>
……
</head>
<body>
……
<environment names="Development">
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
    <link rel="stylesheet" href="~/css/site.css" />
</environment>
<environment names="Staging,Production">
    <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.6/css/bootstrap.min.css"
          asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
          asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
    <link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
</environment>
</body>
</html>

在客户端浏览器中发现返回的结果中并没有<enviroment>标签中的内容,也就是说taghelper没有执行。

但是,在官方文档中是这样描述partial viewview的区别的:

The main difference between how a view and a partial view are rendered is that partial views do not run _ViewStart.cshtml

可是为什么taghelper却在partial view中不工作呢?难道是官方文档的疏忽?

于是我在当前controller对应的视图文件下加入了_ViewImports.cshtml,依然没有作用。

在该视图中直接通过@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers添加,也没有作用。

那么问题出在哪里呢?

蝌蝌的主页 蝌蝌 | 初学一级 | 园豆:158
提问于:2017-03-06 19:33
< >
分享
最佳答案
0

你应该是参考这两篇文章来设置Multiple Environment for develop

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments

https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/intro

会不会是你在Action中 跳转时没有 Environment 参数呀!

可以看一下这个:http://stackoverflow.com/questions/33467222/asp-net-mvc6-setting-webroot-programmatically/33790058#33790058

收获园豆:50
BUTTERAPPLE | 老鸟四级 |园豆:3190 | 2017-03-07 13:08

可以确定不是缺少Environment参数,因为通过View()返回的视图都是正常的。

蝌蝌 | 园豆:158 (初学一级) | 2017-03-07 15:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册