0

I have the below css that come as string from data base

string css = "div{width:200px}.abc{color:red}";

We will fetch this from database and will dump it in to a style tag in mvc view. I am getting the string but displaying as below:

<style type="text/css">
    "div{width:200px}.abc{color:red}"
</style>

Where as it should display as :

<style type="text/css">
    div{
        width:200px
      }
   .abc{
     color:red 
    }
</style>

Can some body advise how can I achieve this? I tried with dotless, but not able to use it because of the problem stated here :(Unable to use Less.Parse using dotless in c#)

Please advise??

Community
  • 1
  • 1
mmssaann
  • 1,507
  • 6
  • 27
  • 55
  • Do you mean the formatting is bad, or the fact that it is between `"` ? If the latter applies, you might try placing it in a literal control? http://stackoverflow.com/questions/5536209/how-to-use-razor-like-aspliteral – Christophe De Troyer Jan 17 '14 at 06:02
  • Please provide more code to get context. How do you create css? What value are you getting from DB? What error do you see? – vmg Jan 17 '14 at 06:03
  • @ Christophe De Troyer, The issue is not just with the "". we may get he less css from database not just pure css. In this case I need to convert less css to normal css. how can I do it? – mmssaann Jan 17 '14 at 06:23

2 Answers2

1

You can try following code,

<style type="text/css">
   @Html.Raw(css)
</style>

Or

<style type="text/css">
   @MvcHtmlString.Create(css)
</style>
Chamika Sandamal
  • 23,565
  • 5
  • 63
  • 86
0

It is working with dotless as below.. dotless.Core.Less.Parse(css)

The formatting is working but still I add some less css in the database the engine is not parsing to css. For ex:

 dotless.Core.Less.Parse("@abc:black")

the engine is not parsing this variable to css, it is just returning blank.. any ideas??

mmssaann
  • 1,507
  • 6
  • 27
  • 55