@(Html.Kendo().DropDownListFor(model => model.ServiceID)
  .OptionLabelTemplate("#=optionLabel#")
  .ValueTemplate("#=Code#(#=Rate#) - #=Description#")
  .Template("#=Code#(#=Rate#) - #=Description#")
  .DataTextField("Code")
  .DataValueField("ServiceID")
  .DataSource(d =>
  {
    d.Read(read =>
    {
      read.Action("GetServiceRepository", "Service").Type(HttpVerbs.Post);
    });

  })
  .Events(e => e.Change("onWorkOrderJobServiceChange"))
  .HtmlAttributes(new { required = "required" })
  .OptionLabel(new { optionLabel = Resources.Wording.SelectOne, ServiceID = 0, Rate = 0, Code = "", Description = "" })
)





我有一个如上所述的下拉列表,想将所选值绑定到模型的ServiceID字段(类型为int

但是,无论我选择哪个项目,ServiceID字段始终为空!它甚至不是可为null的int?类型!

为什么会发生这种情况,我如何才能实现自己的目标?

最佳答案

Kendo DropDownList具有ValuePrimitive。默认情况下,它为false,并且所选项目返回“文本和值”对。

@(Html.Kendo().DropDownListFor(model => model.ServiceID)
  .ValuePrimitive(true)
  ....

10-05 23:14