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

查看:598
本文介绍了如何获得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.

但是由于某种原因您需要使用隐藏字段,请将其放在此处,

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天全站免登陆