asp.net mvc - DropDownList with Enum Kendo UI -


i'm working on updating application use kendo ui , have run issue binding enum dropdownlist. 2 issues having 1) value not contain enum value , instead contains "today" (should 0), , 2) display value "last10days" instead of "last 10 days" in description tag. looked , couldn't find place has used kendo ui display description text , include numerical value instead of text. appreciated.

view

<div class="span6">   @html.labelfor(m=> m.dateranges)   @(html.kendo().dropdownlistfor(m => m.dateranges)       .bindto(enum.getnames(typeof(searchdateranges)).tolist())       .htmlattributes(new { value = "today" })       .datatextfield("text")       .events(e => e.change("datechange"))) </div>  <div class="span6">   @html.labelfor(m => m.status)   @(html.kendo().dropdownlistfor(m=> m.status)       .bindto(enum.getnames(typeof(searchstatuscriteria)).tolist())       .htmlattributes(new {value = "all"})) </div> 

model

    public enum searchdateranges {     [description("today")]     today = 0,      [description("last 10 days")]     last10days = 1,      /// <summary>     /// last 30 days.     /// </summary>     [description("last 30 days")]     last30days = 2,      [description("last 60 days")]     last60days = 3,      [description("last 90 days")]     last90days = 4,      [description("custom date range")]     customrange = 5 } 

}

it appears asking variable name of enum , not description attribute:

.bindto(enum.getnames(typeof(searchdateranges)).tolist()) 

to description attribute you'll have little work. here code found:

public static string getenumdescription(enum value) {     fieldinfo fi = value.gettype().getfield(value.tostring());  descriptionattribute[] attributes =     (descriptionattribute[])fi.getcustomattributes(     typeof(descriptionattribute),     false);  if (attributes != null &&     attributes.length > 0)     return attributes[0].description; else     return value.tostring(); } 

you binding text field "text" doesn't exist in enum.

hope helps.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -