Click here to Skip to main content
15,667,436 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to bind a property from the MVC ViewModel to a toggle button?

What I have tried:

I have tried using basic JQuery to manually bind $('#btnToggle').click()..
then set the HiddenField value to true/false based on the toggle.

I'm sure there's a better solution for control binding in MVC.
Updated 6-Jul-16 7:04am
Suvendu Shekhar Giri 6-Jul-16 2:36am    
Share your model and the relevant section of the view.

If you want to persists something that is not included in a form post (such as if an option is on or off) then the only way to do so is to store the data in a hidden field as you are doing now.
Share this answer

For binding a property in the server's view-model to a JavaScript property at the client side, you can use my WebBinding.

In the client side, you can affect the HTML element according to the JavaScript property. For instance, you can use a JavaScript MVC library (like: AngularJS ng-class or, Knockout css binding, etc...) to toggle class with someting like this Simple HTML Toggle Button.

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900