在kendo ui网格中的下拉列表没有选择任何值

时间:2012-10-28 22:33:57

标签: razor kendo-ui

目前我有内联编辑网格,如下所示,我在coloumn CStatusID中有下拉列表,但是,在尝试保存到数据库时它没有选择值

查看:

@(Html.Kendo().Grid(Model)
    .Name("SList")
        .HtmlAttributes(new { @Style = "align:center; font-size:10px;" })
    .Columns(columns => {
        columns.Bound(p => p.CCID);
        columns.Bound(p => p.CRN);
        columns.Bound(p => p.CStatusID).EditorTemplateName("CStatus
");
        columns.Bound(p => p.DateScheduled).Format("{0:MM/dd/yyyy}");

        columns.Command(commands => commands.Edit()).Width(175);
    })
    //.ToolBar(toolBar => toolBar.Save())
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .Pageable()
    .Sortable()
    .Scrollable()
    .Navigatable()
    .Selectable(selectable => selectable.Mode(GridSelectionMode.Single)
                                        .Type(GridSelectionType.Row))
    .DataSource(dataSource => dataSource        
        .Ajax()
        .PageSize(10)   
        .Model(model => model.Id(p => p.ConsumerID))
        .Read(read => read.Action("Index", "Management"))
        .Update(update => update.Action("Edit", "Management"))

    )
)

我在共享/编辑模板下有CStatus.cshtml:

@(Html.Kendo().ComboBox()
        .Name("Status")
        //.OptionLabel("Select status")
        .DataValueField("OptID")
        .DataTextField("OptName")
        .BindTo((System.Collections.IEnumerable)ViewData["constStatus"])


)

控制器:

public ActionResult Index()
        {
            PopulateConstStatus();
            return View();
        }

private void PopulateConstStatus()
        {
            ViewData["constStatus"] = new EDEntities().COptions
                       .Select(e => new ConfOptModel
                       {
                           OptionID = e.OptID,
                           OptionName = e.OptName,
                           CTypeID = e.CTypeID
                       })
                       .Where(e => e.CTypeID == 2)
                       .OrderBy(e => e.OptName);
        }

模型

public int OptID { get; set; }
public string OptName { get; set; }

[UIHint("CStatus")]
public COptionsModel COptionsModel { get; set; }

2 个答案:

答案 0 :(得分:1)

我遵循这个,它作为一个魅力

http://demos.kendoui.com/web/grid/foreignkeycolumn.html

答案 1 :(得分:1)

尝试在kendo网格中添加以下事件

.Events(events =>
{
    events.Save("TestPointGrid_Save");
})

和以下脚本

<script type="text/javascript">
    function TestPointGrid_Save(e) {
        var companyId = $("#NameoftheDropdownlist").data().kendoDropDownList.value();
        e.model.set("NameoftheDropdownlist", companyId);
    }
</script>

您可以参考this link了解更多信息