Skip to content Skip to sidebar Skip to footer

How To Do An Inline Style With Asp.net Mvc 3 Razor In A Html Helper

I want to do this @Html.TextBoxFor(x => x.BackgroundColor, new { style = 'width: 20px; background-color: @Model.BackgroundColor;' }) Hoever it does not render what is in my Mod

Solution 1:

You are already inside a code block; Razor does not parse within code blocks for other code blocks. The style part of the line should look something like this:

style = "width: 20px; background-color: " + Model.BackgroundColor + ";"

Solution 2:

you should concat your string like "width: 20px; background-color: " +Model.BackgroundColor + ";"

I think.

Post a Comment for "How To Do An Inline Style With Asp.net Mvc 3 Razor In A Html Helper"