简体   繁体   English

修改ASP.NET MVC中的样式表属性

[英]Modify Stylesheet properties in ASP.NET MVC

I am preloading stylesheets inside this method OnResultExecuting(ResultExecutingContext filterContext) in MVC, this is just to make sure that this is done before the actionResult is called when loading the page, and this works fine, my issue is now i want to modify the style sheet background-image property in a class called logo and before the tag is built(code below) and added to the head section in the DOM, I'm wondering if there isn't a way to read(StreamReader?/StreamWriter?) the css file and modify it and save it before the tag is built or something like that, btw Im getting the css file from the server. 我正在MVC中的此方法OnResultExecuting(ResultExecutingContext filterContext)中预加载样式表,这只是为了确保在加载页面时在调用actionResult之前完成此操作,而且效果很好,我的问题是我现在想修改样式工作表background-image属性在一个称为logo的类中,并且在标记构建之前(下面的代码)并添加到DOM的头部中,我想知道是否没有一种读取方法(StreamReader?/ StreamWriter?) css文件并对其进行修改并保存,然后再构建标记或类似的内容,顺便说一句,我从服务器获取了css文件。

foreach (string file in filepath)
{
    if (Path.GetExtension(file).ToLower() == ".css")
    {
        TagBuilder link = new TagBuilder("link");
        link.Attributes["rel"] = "stylesheet";
        link.Attributes["type"] = "text/css";
        link.Attributes["href"] = urlHelper.Content(
            string.Format("~/Content/themes/Theme{0}/{1}",
                setting.ThemeId, Path.GetFileName(file)));

        resources.Add(MvcHtmlString.Create(link.ToString(TagRenderMode.SelfClosing)));
    }
}

您可以在此样式表之后加载另一个样式表,然后以这种方式修改类样式,实际上这正是我为白色标签解决方案执行的操作。

Can´t you use LESS to dinamicaly create your css? 您不能使用LESS来动态创建CSS吗?

http://www.dotlesscss.org/ http://www.dotlesscss.org/

http://karlmendes.com/2010/07/using-less-css-for-net-with-asp-net-mvc-2/ http://karlmendes.com/2010/07/using-less-css-for-net-with-asp-net-mvc-2/

Maybe it will make things easier for you... 也许它将使您的工作更轻松...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM