0

I bought the 'Get Shit Done' UI kit for my latest MVC 5 project, but i can't get the checkbox to work. I am trying to use it for the "Remember me" checkbox on the standard MVC 5 login page.

<label class="checkbox checkbox-blue" for="RememberMe">
  <input type="checkbox" value="" id="RememberMe" name="RememberMe" data-toggle="checkbox" checked>
        Remember me
</label>

It doesn't work though. MVC can't parse the value to anything meaningful.

EDIT: To elaborate a bit. Using the standard Html.CheckboxFor syntax doesn't generate a checkbox the way the UI kit i am using expects. The UI kit needs the checkbox to be in the format specified above, since there is some javascript-code that needs to work on it.

Is there perhaps a way to get the mvc html-helpers to generate a bound checkbox in that custom format?

Ashley Medway
  • 7,151
  • 7
  • 49
  • 71
Jakob Olsen
  • 793
  • 8
  • 13
  • Please define "doesn't work". Does the chekcbox get rendered correctly? Do you get the value back on the server? – Andrei V Apr 22 '15 at 08:39
  • Your checkbox does not have a value. Assuming you want to bind to a `bool` then it would need to be `value="true"`. But why not use `@Html.CheckBoxFor(m => m.RememberMe)` and `@Html.LabelFor(m => m.RememberMe, "Remember me")` so you get 2 way binding out of the box. –  Apr 22 '15 at 08:51
  • Which part of the html is relevant? If you just want to add the `data-toggle="checkbox"` then its just `@Html.CheckBoxFor(m => m.RememberMe, new { data_toggle="checkbox" })` –  Apr 22 '15 at 10:32

1 Answers1

0

You can use Html helpers

@Html.CheckBoxFor(m => m.SomeBooleanProperty, new { @checked = "checked" })

Please look at the link below

link to article on stackoverflow

Community
  • 1
  • 1
Wigle
  • 96
  • 9
  • You do not set `new { @checked = "checked" }` when using `@Html.CheckBoxFor()`. The `checked` attribute is set based on the property your bind to. –  Apr 22 '15 at 08:53
  • @AshleyMedway, No. If the value of `RememberMe` is `false` when the model is passed to the view, then `new { @checked = "checked" }` is just ignored - the checkbox is not checked. That's how model binding works - it binds to your property. –  Apr 22 '15 at 13:05