Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

c# - Load css dynamically in asp.net?

I'm creating a content management system where a user can select a css file from their server and the application will parse and store the css. The application will need to be able to parse the css classes out, record them, and store the css content to be dynamically added to another page where a user can select the different css classes from a drop down. So does anyone know of a way to add css content to a page dynamically, for example from a database? I've found a few projects for parsing the css, here .

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Make a controller which serves the CSS content:

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

Controller code:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...