2016-05-19 30 views
0

這是我在Index.cshtml無法獲得Angularjs NG-包括與網頁API MVC工作

<div ng-show="tab.isSet(1)" ng-include ="'show-employees.html'">  
</div> 

這是表演,employees.html

<h2>List of Employees</h2> 
<div class="panel-body"> 
    <table class="table table-bordered"> 
     <tr> 
      <th>Id</th> 
      <th>FirstName</th> 
      <th>Age</th> 
      <th>Position</th> 
      <th>Salary</th> 
      <th>Department</th> 
     </tr> 
     <tr ng-repeat="employee in employees"> 
      <td>{{employee.Id}}</td> 
      <td>{{employee.FirstName}}</td> 
      <td>{{employee.Age}}</td> 
      <td>{{employee.Position}}</td> 
      <td>{{employee.Salary}}</td> 
      <td>{{employee.Department}}</td> 
     </tr> 
    </table> 
</div> 

PrintScreen of the Solution

我試圖在index.html文件中包含show-employees.html選項卡,但我一直收到404錯誤。我認爲鏈接是問題。

回答

0

你應該使用NG-包括如下:

<div ng-include="template.url"></div> 
+0

我需要包括顯示-employees.html。有我的解決方案的打印屏幕在 – user3809781

0

你的HTML住在美景的/ home /顯示-employees.html

你需要使用的完整路徑,因爲它是一個靜態文件,所以不會通過MVC路由。

0

我不認爲你可以在MVC項目的Views文件夾中訪問HTML文件。

請嘗試以下,看看它爲你工作,

  1. 創建在查看/ Home文件夾模板中的視圖 - ShowEmployees.cshtml
  2. 在家庭控制器

    ,加

    public ActionResult ShowEmployees() { return View(); }

  3. NG-包括= 「 '/主頁/ ShowEmployees'」

+0

謝謝!有效 :) – user3809781