Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

razor editorfor checkbox event binding

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?

like image 665
Michael Brennt Avatar asked Dec 20 '13 09:12

Michael Brennt


1 Answers

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

I suggest you change EditorFor to CheckBoxFor, or if you do want to use the EditorFor, this question suggests to create an editor template.

like image 79
Marthijn Avatar answered Oct 02 '22 13:10

Marthijn