asp.net-mvc - 在 asp.net MVC4 中动态加载 css 文件

标签 asp.net-mvc css

我想知道这样做是否正确 我有一个用于定位手机、平板电脑和浏览器的应用程序。在我正在使用的javascript中。这在 html 页面中工作。现在我已经在 asp.net mvc 4 中迁移了这个应用程序并正确地工作我定义了 rootpath 变量并分配给它 "../"。并将其连接起来,如下所示元素结构如图所示。我想在 index.cshtml View 中使用它,这也是我的默认 View 。

        var userAgent = window.navigator.userAgent;
        var rootpath ="../";
        if (userAgent.indexOf("iPhone") >= 0 || userAgent.indexOf("iPad") >= 0) {
            isiOS = true;
        }
        if (userAgent.indexOf("Android") >= 0 || userAgent.indexOf("iPhone") >= 0) {
            isMobileDevice = true;
            dojo.byId('dynamicStyleSheet').href = rootpath + "styles/mobile.css";

        }
        else if (userAgent.indexOf("iPad") >= 0) {
            isTablet = true;
            dojo.byId('dynamicStyleSheet').href = rootpath + "styles/tablet.css";

        }
        else {
            isBrowser = true;

            dojo.byId('dynamicStyleSheet').href = rootpath + "styles/browser.css";

        }

enter image description here

最佳答案

对于样式,您可以这样做。从 Razor View 中,它应该能够加载您想要的所有样式元素。

<link href="../../AppStyles/templatemo_style.css" rel="stylesheet" type="text/css" />

关于asp.net-mvc - 在 asp.net MVC4 中动态加载 css 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15925598/

相关文章:

ASP.NET MVC : How do you access the session from a different project within the solution?

asp.net-mvc - 无法从 azure 存储正确下载文件,下载文件时数据也会丢失

html - 调整网页大小时的空白

Html - 在更改页面大小时使表单响应

asp.net-mvc - 如何对 MVC 3 应用程序进行表单 POST 并获取反序列化类?

c# - 当查询仅因属性不同时,如何解决 LINQ to Entity 查询重复问题?

asp.net-mvc - asp.net mvc相当于rails回调before_save

javascript - 如何将一个div变成一个复选框

css - 在 ol 的 li 内 float 图像,左侧文本,适用于 Chrome,不适用于 IE/FF

html - 响应 body 中的多个背景图像