This is a migrated thread and some comments may be shown as answers.

Bind switch to a model

1 Answer 245 Views
Switch
This is a migrated thread and some comments may be shown as answers.
JP13
Top achievements
Rank 1
JP13 asked on 24 May 2019, 10:25 PM
I have a switch that I would like to bind to a model, is this possible?     

1 Answer, 1 is accepted

Sort by
1
Tsvetomir
Telerik team
answered on 28 May 2019, 01:15 PM | edited on 25 Jul 2022, 10:55 AM
Hello,

If you would like to bind the Kendo UI Switch widget to a model, it means that you would have to make use of the SwitchFor() HtmlHelper. Here is how to bind it:

Controller which returns the view:

public IActionResult Index()
{
    var model = new OrderViewModel() {
         OrderID=1,
         Discontinued = true
    };
 
    return View(model);
}

View:

@model Sample.Models.OrderViewModel
 
@(Html.Kendo().SwitchFor(m=>Model.Discontinued)
  ...
)

Let me know in case further assistance is needed.


Kind regards,
Tsvetomir
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
commented on 21 Jul 2022, 08:01 AM

When using the SwitchFor, do not specify name separately.
Mihaela
Telerik team
commented on 25 Jul 2022, 10:56 AM

Thank you for the note, Hassan. I have updated the code snippet in the answer.
Tags
Switch
Asked by
JP13
Top achievements
Rank 1
Answers by
Tsvetomir
Telerik team
Share this question
or