2013-04-10 48 views
0

我在想這是一個正確的方法嗎 我有一個應用程序用於定位手機,平板電腦和瀏覽器。在我使用的JavaScript。這是在html頁面中工作。現在,我已經在asp.net mvc的4遷移這個應用程序和工作得當,我定義ROOTPATH varible和assinged它「../」。並將其連接成如下圖所示的項目結構。我想在index.cshtml視圖中使用它,這也是我的默認視圖。在asp.net中加載css文件dynamicall MVC4

 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

回答

1

對於造型你可以做到這way.From Razor視圖,它應能加載所需的所有樣式元素。

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

感謝您的回覆,但我無法忽視您的回答 – user641812 2013-04-11 05:27:49