我想知道这样做是否正确 我有一个用于定位手机、平板电脑和浏览器的应用程序。在我正在使用的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";
}
最佳答案
对于样式,您可以这样做。从 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/