简体   繁体   English

如何在html帮助器中使用asp.net mvc 3 razor进行内联样式

[英]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 Mode.Background color(in firebug I just see @bModel.BackgroundColor"). Is this possible? 然而,它不会呈现我的Mode.Background颜色(在firebug中我只看到@ bModel.BackgroundColor“)。这可能吗?

You are already inside a code block; 你已经在代码块中; Razor does not parse within code blocks for other code blocks. Razor不会在其他代码块的代码块中进行解析。 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 + ";" 你应该把你的字符串连接起来像“width:20px; background-color:”+ Model.BackgroundColor +“;”

I think. 我认为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM