如何在HTML助手中使用ASP.NET MVC 3剃刀做内联样式 [英] How to do an inline style with asp.net mvc 3 razor in a html helper

查看:94
本文介绍了如何在HTML助手中使用ASP.NET MVC 3剃刀做内联样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这样做

@Html.TextBoxFor(x => x.BackgroundColor, new { style = "width: 20px; background-color: @Model.BackgroundColor;" })

但是它不能渲染Mode.Background颜色(在萤火虫中,我只能看到@ bModel.BackgroundColor).这可能吗?

Hoever it does not render what is in my Mode.Background color(in firebug I just see @bModel.BackgroundColor"). Is this possible?

推荐答案

您已经在代码块中; Razor不会在代码块内解析其他代码块.该行的样式部分应如下所示:

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

这篇关于如何在HTML助手中使用ASP.NET MVC 3剃刀做内联样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆