asp.net-mvc - 如何在剃刀视图中添加Html.CheckBox控件中的样式?
我在cshtml中创建了以下复选框列表:
if (control.ControlData == "1") {
@Html.CheckBox(@control.ControlId, true, new { @id = @control.ControlId ,style="position:absolute;left: @string.Concat(@control.LeftLocation,"px"); top:@string.Concat(@control.TopLocation,"px");height:@string.Concat(@control.Height,"px")",@class="checkboxpair" });
@*Basically want to replace the below by the above*@
@*<input type="checkbox" style="position:absolute;left: @string.Concat(@control.LeftLocation @control.Width/2,"px");top:@string.Concat(@control.TopLocation,"px");height:@string.Concat(@control.Height,"px")" class="checkboxpair" id="@control.ControlId" name="@control.ControlId" value="2" />*@
}
我收到一些与以下相关的错误:
,预期
我认为我在Html.Checkbox;
内创建html对象时出错了吗?
基本上,如何为Html.CheckBox
控件设置样式?
提前致谢。
最佳答案:
1 个答案:
答案 0 :(得分:3)
您需要在变量名和字符串文字之间添加
。
你在哪里:
style="blablablabla"px"blablablabla"
应该是
style="blablablabla" px "blablablabla"
,在你的情况下:
@Html.CheckBox(@control.ControlId, true, new {
@id = @control.ControlId,
@class="checkboxpair",
style="position:absolute"
";left:" @string.Concat(@control.LeftLocation, px)
";top:" @string.Concat(@control.TopLocation, px)
";height:" @string.Concat(@control.Height, px)
});
本文经用户投稿或网站收集转载,如有侵权请联系本站。