如何获取 Kendo DropDownList 的选定值 [英] how to get selected value for Kendo DropDownList

查看:30
本文介绍了如何获取 Kendo DropDownList 的选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何确定在我的剑道下拉列表中选择了哪个项目.我的观点将其模型定义为:

I can't figure out how to determine which item is selected in the my kendo dropdownlist. My view defines it's model as:

@model KendoApp.Models.SelectorViewModel

ViewModel 定义为:

The ViewModel is defined as:

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 的值分配给隐藏的表单字段,以便控制器可以使用它?

This DropDownList contains the values I expect but I need to pass the selected value back to my controller when the user clicks the submit button. Everything works fine except I don't have access to which item was selected from the controller's [HttpPost] action. So, how do i assign the DropDownList's value to a hidden form field so it will be available to the controller?

推荐答案

也许你应该像这样使用 Kendo DropDownList 的 DropDownListFor 构造:

Maybe you should be using the DropDownListFor construct of the Kendo DropDownList like so in your view:

@(Html.Kendo().DropDownListFor(m => m.EncSelected)
                    .Name("EncounterTypes")
                    .DataTextField("Description")
                    .DataValueField("ID")
                    .BindTo(Model.ENCTypes)
                    .SelectedIndex(Model.EncSelected)
                )

这样,当您提交时,它将在 POST 请求中可用,您无需在任何地方放置隐藏字段.

This way, when you submit, it will be availble on the POST request and you won't need to put an hidden field anywhere.

但是如果您出于某种原因需要使用隐藏字段,请将其放在那里,订阅下拉列表的选择事件并使用JQuery放置(例如)将所选项目放在隐藏字段上.

BUT should you need to use the hidden field for some reason, put it there, subscribe the the select event of the dropdown list and put using JQuery (for instance) put the selected item on the hidden field.

这是你的选择:)

这篇关于如何获取 Kendo DropDownList 的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆