Reputation: 39
I working on mvc website
i have 2 CSS Files one for Arabic users and the other one for English users
but the first css files add to bundle
like:
bundles.Add(New StyleBundle("~/Content/css").Include("~/Content/site.css"))
i want to add another stylebundle
like:
bundles.Add(New StyleBundle("~/Content/css").Include("~/Content/site.ar.css"))
and change the used one depend on the user selection
Upvotes: 0
Views: 2249
Reputation: 31
Actually it is possible. Here's what I did for my English/French website:
In BundleConfig.cs:
bundles.Add(new StyleBundle("~/Content/css-en-US").Include(
"~/Content/site.en-US.css"));
bundles.Add(new StyleBundle("~/Content/css-fr-FR").Include(
"~/Content/site.fr-FR.css"));
In my View (_Layout.cshtml in my case):
@{
var culture = System.Threading.Thread.CurrentThread.CurrentUICulture.Name.ToLowerInvariant();
}
...
@Styles.Render("~/Content/css-" + culture)
...
I hope this helps.
Upvotes: 3
Reputation: 1456
Bundles are configured during application start (in global.asax), so changing the BundleConfig.cs to work wont help unless the preference to add or remove a css to bundle is available during the application start (which probably is not going to be the case).
So, the other option is to send this new css file to the browser when the user selects the preference as arabic. Technically this means to have a condition in layout to check the preference and include arabic css. However in this case, it will not be part of the bundle.
Upvotes: 1