How to bind a model to a kendo Combobox in order to use the models validatation?

If you use Html.Kendo().ComboBoxFor() you can bind it to a model property similar to this:

@(Html.Kendo().ComboBoxFor(m => m.UnavailableRoles)
    .Name("roleRequest_UnavailableRoles")
    .BindTo(new SelectList(Model.roleRequest.UnavailableRoles, "Value", "Text"))
    .HtmlAttributes(new { name="addRoleName", style = "width:250px", required = true, roleValidationMessage = "foo" })
    .Value(Model.roleRequest.roleName)
    .DataTextField("Text")
    .DataValueField("Value")
    .Filter(FilterType.StartsWith)
    .Placeholder("Select Role...")
    .AutoBind(false)
    .Suggest(true)
)

Note that when doing this, you don’t need the Name() or Value() properties because they will be handled when using the ComboBoxFor()

This will take care of binding the control to the model and also allow you to use the validation.

Also, one thing I missed in your model: You’ll want another property for the actual values (besides just the options). I would do something like this:

public List<Guid> RoleIds { get; set; } // or List<int> if you're using integers

and then change your ComboBoxFor to ComboBoxFor(x => x.RoleIds)

Leave a Comment