what is the correct syntax for using Razor syntax inside a style tag of a view? I tried two different ways:
<style scoped>
.test1
{
background-color: @Model.bgColor;
}
.test2
{
background-color: @(Model.bgColor);
}
</style>
Both versions will break syntax highlighting and code indentation of Visual Studio 2012 (Version 11.0.60610.01 Update 3).
Any idea? Thanks!
Try this:
@{
var mystyle = string.Concat("<style scoped> .test1 { background-color: ", Model.bgColor, "; } .test2 { background-color: ", Model.bgColor, "; } </style>");
}
@MvcHtmlString.Create(mystyle)
Edit
@IngmarBobe sorry, but I tested with these two examples on the same version of VS2012 and working properly.
<style scoped>
.test1
{
background-color: @Model.BgColor;
}
.test2
{
background-color: @(Model.BgColor);
}
</style>
and
@{
<style scoped>
.test1
{
background-color: @Model.BgColor;
}
.test2
{
background-color: @(Model.BgColor);
}
</style>
}
What type of data is "BgColor"?. In my tests "BgColor" is defined in this manner and it works well:
public string BgColor { get { return "#611546"; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With