I don't want to have to round trip for two items? How do I do that in TagHelpers?
1 Answer, 1 is accepted
0
Accepted
Aleksandar
Telerik team
answered on 01 Oct 2021, 11:07 AM
| edited on 06 Oct 2021, 09:00 AM
Hi Russell,
To create a DropDownList with two options using TagHelpers without setting a DataSource configuration you can, for example, use the following definition in the View:
@{ var data = new List<SelectListItem>() { new SelectListItem { Text = "Male", Value = "1" }, new SelectListItem { Text = "Female", Value = "2" } }; } <kendo-dropdownlistname="sex"datatextfield="Text"datavaluefield="Value"bind-to="data"on-change="onChange"></kendo-dropdownlist><script>functiononChange(e) {
alert(e.sender.dataItem().Text)
}
</script>
You can see the above in action in this screencast. The example demonstrates how you can also attach a change event handler. For details on the TagHelper configuration refer to the DropDownList TagHelper section of the documentation.
Regards,
Aleksandar Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Thanks for responding. I was rushing too much and I apologize.
My request is really basic: I need a Sex drop down with "Male" and "Female". I was hoping for a simple hard coded mechanism to add those two items - via taghelpers - to a dropdownlist?
Aleksandar
Telerik team
commented on 06 Oct 2021, 09:00 AM
Thank you for the additional details. I updated the initial answer with an example based on the details provided.