Set class of hidden input created by @html.checkboxfor

1.2k Views Asked by At

i have a view where i dynamically add/ delete checkboxes in a table. I´m using the mvc4 razor engine in my view. With the synatx @Html.CheckboxFor(m=>m.xyz) razor creates two input fields. One with the type checkbox and one with type hidden. If i give a class to the checkbox with @Html.CheckboxFor(m=>m.xyz, new {@class= "CheckboxClass}) only the input field with type checkboxget this class. Is there a easy way to give the class to both input fields?

1

There are 1 best solutions below

0
On

If you really don't like just leaving things the way they are, then you have a couple options.

  • make the input fields yourself.. you are working in an HTML file after all.
  • write some javascript to handle it:

$('.chkClass').each(i,e) {
$('INPUT[name=' + e.name + ' type=hidden]').remove();
}); //untested, and it's very late here.