0

I am working with MVC 4. I want to use model's value to set inline-style. But It didn't work?

style= "background-color:@item.CompanyColor"//It not work
style= "background-color:Black"//It work: background color is black now

And I can use this value to set color like that:

font color="@item.CompanyColor"//it work: font color changed

So, what is the problem here?

tereško
  • 58,060
  • 25
  • 98
  • 150
hoangmeo325
  • 450
  • 2
  • 10
  • 18

2 Answers2

0

Use parenthesis to separate code with style attribute. It should be like this :

style= "background-color: @(item.CompanyColor) "

rajat gogia
  • 3
  • 1
  • 3
0

You can also use Html.Raw html helper

style="background-color: @{Html.Raw(item.CompanyColor);}"
Szakus
  • 81
  • 3