Topic: Asp.Net MVC and Switch
I can't seem to get the standard Asp.Net MVC Checkbox and the switch control to work together. I know that MVC spits out two input boxes and maybe that's the problem, but I need some assistance on wiring that up. I've also tried a simple checkbox and it submits "on" instead of "true" like an MVC box.
Vikas lalwani answered 4 years ago
You can simply Add checkbox CSS and it should work in your MVC app
@Html.CheckBoxFor(m => Model.Checkbox, new { @class = "MDBootstrapclass" })
If this doesn't work, you can also use regular Checkbox with MDBootstrap class
<label class="checkbox">
<input data-val="true"
data-val-required="The Se souvenir de moi? field is required."
id="RememberMe"
name="RememberMe"
type="checkbox"
value="true"
@(Model.RememberMe ? "checked" : "")
><i></i>@ViewRes.Names.RememberMe
</label>
<input name="RememberMe" type="hidden" value="false">
Check this link: https://forums.asp.net/t/2141802.aspx?My+css+code+does+not+work+with+MVC+checkboxFor
You will need the exact HTML when MVC HTML.Checkboxfor is rendered.
OR you can simply create own custom checkbox by using MDBootstrap CSS properties. HTML Custom Checkbox and Radio buttons
Marcin Luczak staff commented 4 years ago
Hi @Vikas lalwani,
Thank you for your help to our community :)
Keep coding, Marcin from MDB
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: Free
- Premium support: No
- Technology: MDB jQuery
- MDB Version: 4.15.0
- Device: Desktop
- Browser: Chrome
- OS: Windows
- Provided sample code: No
- Provided link: No
Grzegorz Bujański staff commented 4 years ago
I'm sorry but we don't have any experience with Asp.Net MVC. It's hard for us to say anything about this.