Tyrone
Tyrone

Reputation: 1

Inline CSS with Razor MVC3

Can anyone please answer to me as why this is not working?

For simplistic purposes propose I have the following:

var raw = "<div style='background:" + color.HexValue + "'></div>";

I am calling it like this:

<td>@Html.Raw(raw)</td>

And it produces the following:

<td><div style=""></div></td>

I have tried so many different ways and nothing seems to have worked. Also could you point me in the right direction to how this should be properly done.

Upvotes: 0

Views: 4258

Answers (3)

Balton
Balton

Reputation: 31

It's easy

<td><div style="background: @'color.HexValue'"></div></td>

Upvotes: 2

Damb
Damb

Reputation: 14600

<div style="background: @color.HexValue;"></div>

Upvotes: 1

Tejs
Tejs

Reputation: 41236

You're overcomplicating this situation I think. You could write the following in your view and get the right thing:

<td><div style="background: @{color.HexValue}"></div></td>

Upvotes: 0

Related Questions