开发者

How to do an inline style with asp.net mvc 3 razor in a html helper

开发者 https://www.devze.com 2023-02-21 05:09 出处:网络
I want to do this @Html.TextBoxFor(x => x.BackgroundColor, new { style = \"width: 20px; background-color: @Model.BackgroundColor;\" })

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 Mode.Background color(in firebug I just see @bModel.开发者_如何学PythonBackgroundColor"). Is this possible?


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 + ";"


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

I think.

0

精彩评论

暂无评论...
验证码 换一张
取 消