问题描述
我无法将事件绑定到@ html.editorfor
I cant bind event to @html.editorfor
我听说它可能与"class"属性的存在有关,但我看不到任何联系.
I've heard it might be connected to presence of "class" attribute but I can see no connection whatsoever.
@Html.EditorFor(model => model.SameAsBaseAddress, new { @onclick = "checkboxcheck()" })
function checkboxcheck() {
//blah...
}
当我使用firebug调试并手动添加处理程序时,一切正常. TextBoxFor,RadioButtonFor等在剃刀事件绑定方面没有问题.
When I debug with firebug and add handler manually all works fine. TextBoxFor, RadioButtonFor etc. have no problems with razor event binding.
该怎么办?
推荐答案
EditorFor
扩展名没有像TextBoxFor
这样的参数htmlAttributes
,请参见: http://msdn.microsoft.com/en -us/library/system.web.mvc.html.editorextensions.editorfor%28v = vs.118%29.aspx
The EditorFor
extension doesn't have an argument htmlAttributes
like the TextBoxFor
, see: http://msdn.microsoft.com/en-us/library/system.web.mvc.html.editorextensions.editorfor%28v=vs.118%29.aspx
我建议您将EditorFor
更改为 CheckBoxFor
,或者如果您确实要使用EditorFor
,建议创建一个编辑器模板.
I suggest you change EditorFor
to CheckBoxFor
, or if you do want to use the EditorFor
, this question suggests to create an editor template.
这篇关于剃刀编辑器,用于复选框事件绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!