【问题标题】:ASP MVC url with angularjs带有 angularjs 的 ASP MVC url
【发布时间】:2014-05-06 10:49:59
【问题描述】:

在 asp web api 中,我有一个带有 angularjs 框架的 index.html。

在 angularjs 我有以下路线:

gestionale.config(function ($routeProvider, $locationProvider) {     
  $routeProvider.
    when('/', {
        templateUrl: 'View/people.html',
        controller: 'mainController'
    }).
    when('/ruoli', {
        templateUrl: 'View/ruoli.html',
        controller: 'ruoliController'
    });
});

当我使用 Visual Studio 启动项目时,它会在以下网址打开 index.html:

http://localhost:49375/index.html#/

视图“View/people.html”正确显示。

1)如何在 index.html 中放置 ruoli.html 页面的静态链接?我试过了

<a href="/ruoli">

但由于它加载页面而不起作用

http://localhost:49375/ruoli

而不是

http://localhost:49375/index.html#/ruoli

【问题讨论】:

    标签: javascript html asp.net asp.net-mvc angularjs


    【解决方案1】:

    你需要把 hashbang 放在斜线之前。

    所以你像这样设置你的 href 属性:

        <a href="#/ruoli">
    

    将正确导航到:

        http://localhost:49375/index.html#/ruoli
    

    查看这篇 hashbang 路由文章/食谱:

    http://fdietz.github.io/recipes-with-angular-js/urls-routing-and-partials/client-side-routing-with-hashbang-urls.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-07
      • 2014-10-22
      • 2021-10-30
      • 1970-01-01
      相关资源
      最近更新 更多