Guest User

Untitled

a guest
Feb 21st, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. <div class="span6">
  2. @Html.LabelFor(m=> m.DateRanges)
  3. @(Html.Kendo().DropDownListFor(m => m.DateRanges)
  4. .BindTo(Enum.GetNames(typeof(SearchDateRanges)).ToList())
  5. .HtmlAttributes(new { value = "Today" })
  6. .DataTextField("Text")
  7. .Events(e => e.Change("DateChange")))
  8. </div>
  9.  
  10. <div class="span6">
  11. @Html.LabelFor(m => m.Status)
  12. @(Html.Kendo().DropDownListFor(m=> m.Status)
  13. .BindTo(Enum.GetNames(typeof(SearchStatusCriteria)).ToList())
  14. .HtmlAttributes(new {value = "All"}))
  15. </div>
  16.  
  17. public enum SearchDateRanges
  18. {
  19. [Description("Today")]
  20. Today = 0,
  21.  
  22. [Description("Last 10 Days")]
  23. Last10Days = 1,
  24.  
  25. /// <summary>
  26. /// The last 30 days.
  27. /// </summary>
  28. [Description("Last 30 Days")]
  29. Last30Days = 2,
  30.  
  31. [Description("Last 60 Days")]
  32. Last60Days = 3,
  33.  
  34. [Description("Last 90 Days")]
  35. Last90Days = 4,
  36.  
  37. [Description("Custom Date Range")]
  38. CustomRange = 5
  39. }
  40.  
  41. .BindTo(Enum.GetNames(typeof(SearchDateRanges)).ToList())
  42.  
  43. public static string GetEnumDescription(Enum value)
  44. {
  45. FieldInfo fi = value.GetType().GetField(value.ToString());
  46.  
  47. DescriptionAttribute[] attributes =
  48. (DescriptionAttribute[])fi.GetCustomAttributes(
  49. typeof(DescriptionAttribute),
  50. false);
  51.  
  52. if (attributes != null &&
  53. attributes.Length > 0)
  54. return attributes[0].Description;
  55. else
  56. return value.ToString();
  57. }
  58.  
  59. public static List<SelectListItem> EnumToSelectList( Type enumType )
  60. {
  61. return Enum
  62. .GetValues( enumType )
  63. .Cast<int>()
  64. .Select( i => new SelectListItem
  65. {
  66. Value = i.ToString(),
  67. Text = Enum.GetName( enumType, i ),
  68. }
  69. )
  70. .ToList()
  71. }
  72.  
  73. .BindTo( EnumToSelectList( typeof( SearchDateRanges ) ) )
  74.  
  75. @(Html.Kendo().Grid<NameProved.Models.Issuer>()
  76. .Name("IssuerGrid")
  77. .Columns(columns =>
  78. {
  79. columns.Bound(issuer => issuer.ID);
  80. columns.Bound(issuer => issuer.Name);
  81. columns.Bound(issuer => issuer.IssuerType);
  82.  
  83. columns.Command(commands =>
  84. {
  85. commands.Edit();
  86. commands.Destroy();
  87. }).Title("Commands");
  88. })
  89. .ToolBar(toolbar => toolbar.Create())
  90. .Editable(editable => editable
  91. .Mode(GridEditMode.PopUp)
  92. )
  93. .DataSource(datasource =>
  94. datasource
  95. .Ajax()
  96. .Events(events => events.Error("grid_error"))
  97. .Model(model =>
  98. {
  99. model.Id(issuer => issuer.ID);
  100. model.Field(issuer => issuer.ID).Editable(false).DefaultValue(0);
  101. })
  102. .Create(create => create.Action("Issuer_Create", "Admin"))
  103. .Read(read => read.Action("Issuer_Read", "Admin"))
  104. .Update(update => update.Action("Issuer_Update", "Admin"))
  105. .Destroy(destroy => destroy.Action("Issuer_Destory", "Admin"))
  106. )
  107. .Pageable()
  108.  
  109. )
  110. )
  111.  
  112. @model NameProved.Models.IssuerType
  113.  
  114. @Html.EnumDropDownListFor(issuerType => issuerType)
  115.  
  116. public class Issuer
  117. {
  118.  
  119. public int ID { get; set; }
  120. public string Name { get; set; }
  121.  
  122. [UIHint("IssuerTypeEditor")]
  123. public IssuerType IssuerType { get; set; }
  124. }
  125.  
  126. @(Html.Kendo().DropDownList()
  127. .Name("subscriptionTypeTest")
  128. .DataTextField("Text")
  129. .DataValueField("Value")
  130. .BindTo(Html.GetEnumSelectList(typeof(SubscriptionType)))
  131. .Deferred()
  132. )
  133.  
  134. @(Html.Kendo().DropDownListFor(model => model.NoticePeriodType)
  135. .DataTextField("Text")
  136. .DataValueField("Value")
  137. .DataSource(source =>
  138. {
  139. source.Read(read =>
  140. {
  141. read.Action("LoadPeriodTypesAjax", "ControllerName"); //put controller name
  142. });
  143. })
  144. )
  145.  
  146.  
  147. public JsonResult LoadPeriodTypesAjax()
  148. {
  149. var values = Enum.GetValues(typeof(PeriodType)).Cast<int>(); //PeriodType= enum name
  150. var converter = TypeDescriptor.GetConverter(typeof(PeriodType));
  151. var datas = from value in values
  152. select new SelectListItem
  153. {
  154. Text = converter.ConvertToString(value),
  155. Value = value.ToValue(),
  156. };
  157. return Json(datas, JsonRequestBehavior.AllowGet);
  158. }
  159.  
  160. @(Html.Kendo().DropDownList()
  161. .Name("subscriptionTypeTest")
  162. .DataTextField("Text")
  163. .DataValueField("Value")
  164. .BindTo(EnumHelper.GetSelectList(typeof(SubscriptionType)))
  165. .Deferred()
  166. )
Add Comment
Please, Sign In to add comment