【问题标题】:Route MVC 4 application url - css and js not working路由 MVC 4 应用程序 url - css 和 js 不起作用
【发布时间】:2014-01-13 06:41:56
【问题描述】:

我已经为路由做了这么多

routes.MapRoute(
    name: "Hidden1",
    url: "EditCategoryDetails/{categoryId}",
    defaults: new { controller = "TestController", action = "EditCategory", categoryId = UrlParameter.Optional 
});


routes.MapRoute(
    name: "Hidden2",
    url: "CategoryDetails",
    defaults: new { controller = "TestController", action = "CategoryView" 
});

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "LoginController", action = "Login", id = UrlParameter.Optional
});

完成此操作后,控制器和操作名称已从 Url 中删除,并分别替换为 EditCategoryDe​​tails 和 CategoryDe​​tails。

问题是路由后 js and css won't work 而 url 是 localhost/mywebsite/CategoryDe​​tails

当我在地址栏末尾手动放置 斜杠(//) 时,它正在工作

localhost/mywebsite/CategoryDe​​tails/

搜索完js和css的问题我也做了这个

routes.IgnoreRoute("{file}.css");
routes.IgnoreRoute("{file}.js");
routes.IgnoreRoute("{file}.jpg");
routes.IgnoreRoute("{file}.gif");

但没有希望。 js和css只有在浏览器地址栏最后手动添加slash(/)时生效。

我在_Layout.cshtml页面中包含js和css为

  <link href="~/Content/Site.css" rel="stylesheet" />
  <script src="~/Scripts/jquery-1.7.1.js"></script>

等等

【问题讨论】:

  • 你能发布你如何尝试包含 js 和 css
  • 请检查。我也添加了 dat @VolodymyrBilyachat

标签: asp.net-mvc asp.net-mvc-4 asp.net-mvc-routing url-routing


【解决方案1】:

说得对。我网站的一些脚本被引用为

 <script src="../Scripts/jquery-1.7.1.js"></script>
 <script src="../Scripts/jquery.easing.1.3.js"></script>

而不是

<script src="~/Scripts/jquery-1.7.1.js"></script>
<script src="~/Scripts/jquery.easing.1.3.js"></script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-23
    • 2018-03-11
    • 1970-01-01
    • 1970-01-01
    • 2021-02-13
    • 2023-03-15
    • 2012-08-04
    相关资源
    最近更新 更多