I cant bind event to @html.editorfor
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...
}
When I debug with firebug and add handler manually all works fine. TextBoxFor, RadioButtonFor etc. have no problems with razor event binding.
What to do?
Modify your EditorFor to use the following instead. I've used this to add html attributes (including classes and onclick) to an EditorFor which generates a checkbox.
You can add more attributes as a comma separated list:
The
EditorFor
extension doesn't have an argumenthtmlAttributes
like theTextBoxFor
, see: http://msdn.microsoft.com/en-us/library/system.web.mvc.html.editorextensions.editorfor%28v=vs.118%29.aspxI suggest you change
EditorFor
toCheckBoxFor
, or if you do want to use theEditorFor
, this question suggests to create an editor template.