聚合物网络组件不能与asp.net core 2.0剃刀页面一起使用

时间:2017-10-06 11:29:02

标签: polymer asp.net-core-2.0 polymer-2.x razor-pages

我创建了一个非常简单的 ASP.NET CORE 2.0 项目并选择了新的 Razor Page模板,然后我从主页中删除了所有内容并添加了 Paper-button web组件以便使用它以下是我的 Index.cshtml

的代码
page
@model IndexModel
@{
    ViewData["Title"] = "Home page";
}

<paper-button raised>My Button</paper-button>

然后我在我的文件 Layout.cshtml 中添加了此组件的import语句,如下所示:这就是它现在的样子:

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, minimum-scale=1, 
    initial-scale=1, user-scalable=yes">
    <title>@ViewData["Title"] - DineAlong</title>

    //notice the following script for pollyfills and then the import for paper-button
    <script src="/bower_components/webcomponentsjs/webcomponents-loader.js">
    </script>
    <link rel="import" href="/bower_components/paper-button/paper-button.html">
    <environment include="Development">
        <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
        <link rel="stylesheet" href="~/css/site.css" />
    </environment>
    <environment exclude="Development">
        <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/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>
</head>
  

运行html页面后,只显示文字 MyButton ,并且不显示该地方的纸质按钮。

注意:**我有一个** bower_components 文件夹以及Layout.cshtml和Index.cshtml,即:在 Pages文件夹内,因此布局文件中的引用导入应该工作得很好。

以下是控制台中的错误我可以看到错误,但我不知道它为什么会发生。

error console

文件夹结构

enter image description here

1 个答案:

答案 0 :(得分:0)

您需要将目录移动到wwwroot文件夹下(可能位于lib下)。 Pages目录仅由MVC路由引擎引用,而不是Web服务器引用。

例如,我将Font Awesome添加到我的项目中,可以像:

一样引用它
<link rel="stylesheet" href="~/lib/font-awesome/css/font-awesome.css">

enter image description here