我如何从mvc中的kendo ui网格中的下拉列表中获取选定值

时间:2012-07-14 13:00:49

标签: asp.net-mvc-3 razor kendo-ui

我正在使用asp.net mvc razor开发Kendo UI。我试图将数据库表数据与支持CRUD操作的kendo网格绑定。在这里,我需要为我的一个表字段填充一个下拉列表。我使用了以下代码

查看:

@model IEnumerable<MvcApplication1.PriceOption>    
@(Html.Kendo().Grid(Model)
        .Name("Grid")
        .Columns(columns =>
        {
            //columns.Bound(p => p.ProductTitle).ClientTemplate("<input type='checkbox' disabled='disabled'name='Discontinued' <#= Discontinued? checked='checked' : '' #> />");
            columns.Bound(p => p.ProductTitle).EditorTemplateName("OptionalEmail");
            columns.Bound(p => p.OptionTitle);
            columns.Bound(p => p.Price);
            columns.Bound(p => p.Frequency);
            columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);



        })
        .ToolBar(toolbar => toolbar.Create())
            .Editable(editable => editable.Mode(Kendo.Mvc.UI.GridEditMode.InLine))
        .Pageable()
        .Sortable()
        .Scrollable()
        .DataSource(dataSource => dataSource
            .Ajax()
            .Events(events => events.Error("error_handler"))
            .Model(model => model.Id(p => p.ProductID))
            .Create(create => create.Action("CreateOption", "ZiceAdmin"))
            .Read(read => read.Action("Read", "ZiceAdmin"))
            .Update(update => update.Action("UpdateOption", "ZiceAdmin"))
            .Destroy(update => update.Action("DeleteOption", "ZiceAdmin"))
        )
    )

OptionalEmail.cshtml

@model string
@(Html.Kendo().DropDownList()
    .Name("ProductTitle")
    .Value(Model)
    .SelectedIndex(0)
    .BindTo(new SelectList(ViewBag.ProductTitle))
 )

这里我需要存储下拉列表中的所选项目。但它总是显示为null。我如何从下拉列表中获取所选值。

1 个答案:

答案 0 :(得分:-1)

这是一个错误。删除名称,它将作为ViewModel

的一部分提交回服务器
@model string 
@(Html.Kendo().DropDownList() 
    .Value(Model) 
    .SelectedIndex(0) 
    .BindTo(new SelectList(ViewBag.ProductTitle)) 
 )