2016-10-02 100 views
2

试图在Visual Studio社区中的ASP.NET 5中制作自定义聚合物元素。我选择“新建项目” - >“Web” - > ASP.NET核心Web应用程序(.NET Core)。在Solution Explorer中我添加了一个新的文件“的helloworld.html”,在该文件中创建一个新的聚合物元件使用此代码:ASP.net中的聚合物5

<link rel="import" href="https://polygit.org/components/polymer/polymer.html"> 
<dom-module id="hello-world"> 
    <style></style> 
    <template> 
    <h1>Hello world</h1> 
    </template> 
</dom-module> 
<script> 
    Polymer({ 
     is: "hello-world" 
    }); 
</script> 

接下来,我尝试实施(补充)这个元素的DOM是是由ASP.NET 5创建的,所以我对这两个文件进行了更改index.cshtml_layout.cshtml

文件index.cshtml是:

@{ 
    ViewData["Title"] = "Home Page";  
} 

<link rel="import" href="~/helloworld.html"/> 

<div class="row"> 
    <hello-world></hello-world> 
</div> 

_layout.cshtml我添加的两行代码:

<link rel="import" href="https://polygit.org/components/polymer/polymer.html"> 
<script src="https://polygit.org/components/webcomponentsjs/webcomponents-lite.js"></script> 

接下来,我点击了调试,但没有的Hello World屏幕。只有页眉和页脚从_layout.cshtml

+0

在“应用程序Insights Request GET”中,在调试时,有以下注释:_response code 404_。旁边还有一颗红色钻石。 –

+0

请不要使用ASP.NET 5标记,它不会再这样调用。它是ASP.NET Core并且支持1.0的版本。* – Tseng

回答

0

我觉得

<link rel="import" href="~/helloworld.html"/> 

必须{...}

如果不是外面,看看源的HTML代码,并使用F12( IE/Chrome ...调试器),请参阅网络选项卡以查找错误。

+0

我不知道如何编辑问题。你写的代码在{...}之外,至于网络错误,我在这个问题下面写了这个错误:“ 在调试时,”Application Insights Request GET“中有注释:响应代码404。 t find/import _helloworld.html_ file“ –

+0

reedit这个问题 - 你写的代码在{...} –

+0

之外你把helloworld.html文件放在哪里?它必须在wwwroot文件夹中才能正常工作。 –

0

除了已经建议。您确定

<link rel="import" href="https://polygit.org/components/polymer/polymer.html"> 
<script src="https://polygit.org/components/webcomponentsjs/webcomponents-lite.js"></script> 

是在正确的地方吗?加载页面,打开开发人员工具(F12),并在HTML/DOM视图/资源管理器中检查这些行实际出现在加载页面的<head>标记中。默认的ASP.NET Core模板在_Layout.cshtml中包含<environment>标签。在我的测试中,我首先将链接放入错误的环境中。现在它适用于我。