2016-10-02 44 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>標籤。在我的測試中,我首先將鏈接放入錯誤的環境中。現在它適用於我。