How to bind enum property to dropdownlist in grid for inline editing?

1 Answer 1868 Views
DropDownList Grid
Jay
Top achievements
Rank 1
Iron
Iron
Jay asked on 02 Jul 2021, 06:20 PM

I have a grid and I'm doing inline editing. I have a property in my model that is an enum. Using the Display() attribute on the enum works great for rendering the grid. But when I go to edit a row I have not been able to get a dropdownlist with the enum values to display.

I have a partial view in the EditorTemplates for the enum.

@model Dashboard.Web.Models.Schedule

@(Html.Kendo().DropDownListFor(m => m.GotoType)       
        .DataTextField("Text")
        .DataValueField("Value")
        .BindTo(Html.GetEnumSelectList(typeof(Dashboard.Web.Models.GotoType)))
        .Deferred()
    )

My model  I have the UIHint attrbute on the enum property.

public class Schedule
{
        [Key]
        public int Id { get; set; }
     
        [Display(Name = "Go To ")]
        [UIHint("GotoTypeEditor")]
        public GotoType GotoType { get; set; }

        [ForeignKey("Location"), Display(Name = "Location")]
        public int LocationId { get; set; }
        public Location Location {get; set;}
}

What do I need to do in the Kendo.Grid? I tried adding the EditorTemplateName this did not work. Do i need to do something in the datasource.Model definition?

 

Jay
Top achievements
Rank 1
Iron
Iron
commented on 02 Jul 2021, 07:13 PM | edited

I have the dropdownlist displaying in the grid now. I changed the bindTo to Html.GetEnumSelectList<Dashboard.Web.Models.GotoType>(). But the data binding to my model property is not working.

1 Answer, 1 is accepted

Sort by
0
Jay
Top achievements
Rank 1
Iron
Iron
answered on 02 Jul 2021, 08:36 PM
My problem was in the editor template for the Enum. Here is the correct code. 
@model Enum

@(Html.Kendo().DropDownListFor(m => m)
        .DataTextField("Text")
        .DataValueField("Value")
        .BindTo(Html.GetEnumSelectList<Dashboard.Web.Models.GotoType>())        
    )

Tags
DropDownList Grid
Asked by
Jay
Top achievements
Rank 1
Iron
Iron
Answers by
Jay
Top achievements
Rank 1
Iron
Iron
Share this question
or