我不知道如何确定在我的剑道下拉列表中选择了哪个项目。我的观点将其模型定义为:
@model KendoApp.Models.SelectorViewModel
ViewModel 定义为:
public class SelectorViewModel
{
//I want to set this to the selected item in the view
//And use it to set the initial item in the DropDownList
public int EncSelected { get; set; }
//contains the list if items for the DropDownList
//SelectionTypes contains an ID and Description
public IEnumerable<SelectionTypes> ENCTypes
}
在我看来,我有:
@(Html.Kendo().DropDownList()
.Name("EncounterTypes")
.DataTextField("Description")
.DataValueField("ID")
.BindTo(Model.ENCTypes)
.SelectedIndex(Model.EncSelected)
)
此 DropDownList 包含我期望的值,但当用户单击提交按钮时,我需要将所选值传递回我的控制器。一切工作正常,除了我无权访问从控制器的 [HttpPost] 操作中选择的项目。那么,如何将 DropDownList 的值分配给隐藏表单字段,以便控制器可以使用它?
对于任何想知道如何在 JavaScript 中获取所选值的人来说,这是正确的答案:
$("#EncounterTypes").data("kendoDropDownList").value();
从文档中:http://docs.telerik.com/kendo-ui/api/javascript/ui/dropdownlist#methods-value http://docs.telerik.com/kendo-ui/api/javascript/ui/dropdownlist#methods-value
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)