简体   繁体   English

如何在更改事件中从Kendo()。DropDownList()的DataValueField()中获取值

[英]How to take value from DataValueField() of a Kendo().DropDownList() on change event

I'm using kendo grid and editor template for showing my data. 我正在使用Kendo网格和编辑器模板来显示我的数据。 in editor I've given id to DataValueField() and name to DataTextField() of kendo dropdown list. 在编辑器中,我将id赋予了DataValueField(),并将名字赋予了剑道下拉列表的DataTextField()。 In change event, I'm not able to get the DataValueField(). 在更改事件中,我无法获取DataValueField()。 see the following code 看下面的代码

This is my editor template MemoCarrier.chtml 这是我的编辑器模板MemoCarrier.chtml

@using System.Collections
@(Html.Kendo().DropDownList()
  .DataValueField("PARTNERID")
  .DataTextField("PARTNERNAME")

  .Name("AIRLINENAME")
  .BindTo((IEnumerable)ViewBag.lstAirline)
  .HtmlAttributes(new { maxlength = "", @class = "MNum" })
 .OptionLabel("-Select-Flight ")
 .Filter(FilterType.Contains)
 .Events(e =>
 {
   e.Change("MemoCarrier");
 })
)

Here is my on change function 这是我的变更功能

function MemoCarrier(e) {
    var AirlineName = this.value();
    alert(AirlineName) //it displays PARTNERNAME instead of PARTNERID
}

Currently I'm getting name ie;DataTextField() value. 目前,我正在获取名称,即; DataTextField()值。 instead of that, I need DataValueField(). 相反,我需要DataValueField()。 Thanks for suggestions in advance! 预先感谢您的建议!

so based on your comment the easiest way to do this would probably use the data-bind attribute to simplify the process of binding the model. 因此,根据您的评论,最简单的方法可能是使用data-bind属性简化绑定模型的过程。 Assuming you are using the MVC helper for the grid as well. 假设您也在网格中使用MVC帮助器。

so taking your code and adding this: 因此,将您的代码并添加以下内容:

@(Html.Kendo().DropDownList()
  .DataValueField("PARTNERID")
  .DataTextField("PARTNERNAME")

  .Name("AIRLINENAME")
  .BindTo((IEnumerable)ViewBag.lstAirline)
  .HtmlAttributes(new { maxlength = "", @class = "MNum", data_bind="value:{yourProperyNameHere}" })
 .OptionLabel("-Select-Flight ")
 .Filter(FilterType.Contains)

)

So hopefully you can see all I am doing is adding a new HtmlAttribute property to the control for you. 因此,希望您能看到我正在做的就是为您的控件添加一个新的HtmlAttribute属性。 All you need to do is put whatever property is meant to be the value for this. 您需要做的就是将任何属性指定为此值。

Depending on if this value is a complex ( object ) or simple ( string, int etc ) primitive type you may need to set the Primitive property to true so that only the valuefield eg the id you are assigning is bound back to the grid's row model. 根据此值是复杂的( object )还是简单的( string, int etc )原始类型,您可能需要将Primitive属性设置为true以便仅将值字段(例如,您要分配的id)绑定回网格的行模型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM