c# - 在 asp.net 中动态加载 css?

标签 c# asp.net css

我正在创建一个内容管理系统,用户可以在其中从他们的服务器中选择一个 css 文件,应用程序将解析并存储该 css。应用程序需要能够解析出 css 类,记录它们,并存储要动态添加到另一个页面的 css 内容,用户可以从下拉列表中选择不同的 css 类。那么有没有人知道一种动态地将 css 内容添加到页面的方法,例如从数据库中添加?我找到了一些用于解析 css 的元素,here .

提前致谢。

最佳答案

制作一个提供 CSS 内容的 Controller :

<link rel="stylesheet" href="@Url.Action("GetCss", "Serve", new {id="filename"})" />

Controller 代码:

public class ServeController: Controller
{
    public ContentResult GetCss(string id)
    {
        string cssBody = GetCssBodyFromDatabase(id);
        return Content(cssBody, "text/css");
    }
}

关于c# - 在 asp.net 中动态加载 css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6984718/

相关文章:

javascript - n字+样式后单行文字如何拆分?

c# - Microsoft.Net.Http.Server.WebListenerException(0x80004005): The prefix 'https://+:44384/' is already registered

c# - 将页码添加到 Pdf 文档

c# - 使用图形 API 在 Azure AD B2C 中创建具有自定义属性的用户

c# - asp.net 核心 mvc 导航不适用于 Angular 2

asp.net - 在 Fiddler 中看不到 WebClient post 请求

java - Main.axml打不开VS2015

ASP.NET MVC : How do other people apply conditional CSS classes?

css - 既不使用脚本也不使用伪 CSS 功能也不使用复选框的纯 CSS 移动菜单

css - IE 6 & 7 - 相对输入框越界