Question: Correct way of defining a variable for css theme on MVC

Question

Correct way of defining a variable for css theme on MVC

Answers 0
Added at 2016-12-23 20:12
Tags
Question

I choose a css theme on my BundleConfig and I only load the required css files on the shared view. At the time of rendering another view I'm loading other css files, including the string name of the theme.

For example:

bundle config

string themeSelected = "theme-1";
bundles.Add(new StyleBundle("~/Material/css").Include(
            "~/css/" + themeSelected + "/bootstrap.css",
            "~/css/" + themeSelected + "/materialadmin.css",
            "~/css/" + themeSelected + "/font-awesome.min.css",
            "~/css/" + themeSelected + "/material-design-iconic-font.min.css",
            "~/css/" + themeSelected + "/libs/toastr/toastr.css" ));

on layout

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title - My ASP.NET Application</title>
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    @Styles.Render("~/Material/css")
    @RenderSection("AnotherStyles", required: false)
</head>
<body class="menubar-hoverable header-fixed ">
....

And when i load others partial view for exaple i have

@section SPAViews {
    @Html.Partial("_Home")
}
@section AnotherStyles{
    <link type="text/css" rel="stylesheet" href="~/css/**I NEED INSERT THE THEME VARIABLE DEFINED ON BUNDLE** /libs/morris/morris.core.css">
}

...

another view

@using Xozo.HtmlHelpers
@model IEnumerable<Xozo.Models.PRODUCT>
@section AnotherStyles
{
    <link type="text/css" rel="stylesheet" href="~/css/" + I NEED INSERT THE THEME VARIABLE DEFINED ON BUNDLE + "/libs/DataTables/jquery.dataTables.css">
    <link type="text/css" rel="stylesheet" href="~/css/" + AGAIN I NEED IT + "/libs/DataTables/extensions/dataTables.tableTools.css">
}

Does there exist a way to do that with a kind of global variable? Can anyone suggest what the best practice would be?

I thank you in advance. :)

Answers to

Correct way of defining a variable for css theme on MVC

Source Show
◀ Wstecz