c# - MVC 4 _Layout.cshtml dynamic CSS -
i have problem trying have default css page, depending on aspects can have css changed. groups of people can have css changed own custom version via database entries, post long string has css needs set to. but, can simple , want overwrite maybe background or entire site.
<head> <link href="/static/css/styles.css" rel="stylesheet" /> <style type="text/css"> @{ webextensionhelper.customcss(); } </style> </head>
webextensionhelper.customcss() returns string css in it, stated previously. need affect every page need on _layout.cshtml page. thing consider if it's helpful, have 200 people customcss.
one solution generate custom css file @ run time. in layout can point stylesheet link controller action instead of actual file:
<link href="@url.action("index", "style", new { whichstyle = myvalue })" rel="stylesheet" type="text/css" />
in style controller, create index method:
public actionresult index(string whichstyle) { mystyleviewmodel model = new mystyleviewmodel(); // -- (load relevant style settings here) -- response.contenttype = "text/css"; return view(model); }
and in index view, write out css normal:
@model mystyleviewmodel @{ layout = null; } body { color:#333; @if (model.font == "lucida") { @:font-family:"lucida grande", sans-serif; } else { @:font-family:georgia, serif; } }
i haven't run exact view code, adjust needed situation.
Comments
Post a Comment