【问题标题】:Angularjs + MVC - TemplateUrl cannot be foundAngularjs + MVC - 找不到 TemplateUrl
【发布时间】:2017-05-22 00:57:54
【问题描述】:

您好,我一直在学习有关 Angular 的 Asp.net Core 教程。但我只对角度部分感兴趣,我没有使用 Asp.net 核心。 我处于您可以通过使用此方法轻松地将任何部分 html 包含到我的 mvc/asp/angular 应用程序的部分:

主模块

(function(){
    "use strict";
    angular.module("app-test", ["simpleControls"]);
})();

指令

(function () {

    "use strict";

    angular.module("simpleControls", [])
        .directive("waitCursor", waitCursor);

    function waitCursor() {
        return {      
            templateUrl: "/Views/Helper/WaitCursor.html"
        };
    }
})();

部分 html - 位于 Views/Helper/

<div class="text-center">
    <i class="fa fa-spinner fa-spin"></i> Loading...
</div>

主 html

<wait-cursor ng-show="true"></wait-cursor>

错误 似乎找不到要找的东西

我尝试过: templateUrl: "~/Views/Helper/WaitCursor.html"

templateUrl: "Views/Helper/WaitCursor.html"

templateUrl: "WaitCursor.html" -> 包含主根文件夹中的文件

为什么它可以在 ASP Core 中工作,正如我在教程中看到的那样,但不能在正常的 asp.net mvc 4(我正在使用的)中以及如何解决这个问题。

【问题讨论】:

    标签: asp.net angularjs asp.net-mvc-4


    【解决方案1】:

    ~/Views 文件夹内的文件受到保护,无法直接提供给客户端。它们的目的是仅在服务器上使用和呈现,而不是作为静态文件返回给客户端。

    如果您想使用有角度的 HTML 模板,请将它们放在某个 ~/public/templates 文件夹(或您喜欢但在 ~/Views 之外的某个文件夹)中,这些文件夹可以从客户端浏览器中调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多