如何指定剃刀数据属性,例如,数据外部ID =" 23151"在@ this.Html.CheckBoxFor(...) [英] How to specify data attributes in razor, e.g., data-externalid="23151" on @this.Html.CheckBoxFor(...)
本文介绍了如何指定剃刀数据属性,例如,数据外部ID =" 23151"在@ this.Html.CheckBoxFor(...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@ this.Html.CheckBoxFor(M = GT; m.MyModel.MyBoolProperty,新{@类=myCheckBox,extraAttr =23521})
使用剃须刀,我无法用于数据的属性,如数据外部ID =23521
有没有办法做到这一点使用 @ this.Html.CheckBoxFor(...)
?
解决方案
@ Html.CheckBoxFor(
M => m.MyModel.MyBoolProperty,
新{
@class =myCheckBox
data_externalid =23521
}
)
的 _
将自动转换为 -
在生成的标记:
<输入类型=复选框NAME =MyModel.MyBoolProperty数据外部ID =23521级=myCheckBox/>
和对于服用 htmlAttributes
匿名对象作为参数,不仅 CheckBoxFor
帮助所有HTML佣工是真的。
@this.Html.CheckBoxFor(m => m.MyModel.MyBoolProperty, new { @class="myCheckBox", extraAttr="23521"})
With razor, I'm unable to specify values for data- attributes such as data-externalid="23521"
Is there a way to do this using @this.Html.CheckBoxFor(...)
?
解决方案
@Html.CheckBoxFor(
m => m.MyModel.MyBoolProperty,
new {
@class = "myCheckBox",
data_externalid = "23521"
}
)
The _
will automatically be converted to -
in the resulting markup:
<input type="checkbox" name="MyModel.MyBoolProperty" data-externalid="23521" class="myCheckBox" />
And that's true for all Html helpers taking a htmlAttributes
anonymous object as argument, not only the CheckBoxFor
helper.
这篇关于如何指定剃刀数据属性,例如,数据外部ID =&QUOT; 23151&QUOT;在@ this.Html.CheckBoxFor(...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文