我正在创建一个内容管理系统,用户可以在其中从他们的服务器中选择一个 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/