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

核能气质少年 提交于 2019-12-10 19:09:18

问题


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?


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



回答2:


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

I think.



来源:https://stackoverflow.com/questions/5481412/how-to-do-an-inline-style-with-asp-net-mvc-3-razor-in-a-html-helper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!