user641812
user641812

Reputation: 335

Load css file dynamically in asp.net MVC4

I wonder is this a correct way to do I have an application used to target mobile, tablet and browser. In javascript I'm using. this is working in html page. Now I have migrated this app in in asp.net mvc 4 and to work it properly I defined rootpath variable and assigned it "../". and concatenated it as shown below structure of project is given in image. I want to use it in index.cshtml view which is also my default 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

Upvotes: 0

Views: 231

Answers (1)

Thapediso Motshabi
Thapediso Motshabi

Reputation: 21

For styling you can just do it this way.From Razor view it shall be able to load all the style elements that you want.

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

Upvotes: 1

Related Questions