Kendo UI下拉菜单从模型加载数据

Kendo UI Drop Down loading data from model

本文关键字:加载 数据 模型 UI 下拉菜单 Kendo      更新时间:2023-09-26

我有一个带有产品选择的标准订单。我正在根据以下内容创建一个下拉列表,其中ProductName和ID是产品参考数据模型的属性。ProductID是Order模型的属性。下拉列表已加载,并且在提交表单时工作正常。

我的问题是当用户再次打开此表单以查看他的订单时。我从数据库加载Order模型,可以看到ProductID被正确地加载回来。但是,下拉选择仍然为空。这是标准行为吗?也许我需要执行一些额外的任务。kendo ui不是自动翻译产品ID以在下拉列表中显示产品名称吗?

@model int
@(Html.Kendo().DropDownList()
    .Name("ProductID") 
    .OptionLabel(" ")
    .DataTextField("ProductName")
    .DataValueField("ID")
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("RefDataClientSelection_Read", "RefDataClient").Type(HttpVerbs.Post); //Set the Action and Controller name
        })
        .ServerFiltering(true); //If true the DataSource will not filter the data on the client.
    })
)

尝试使用DropDownListFor(),如下所示:

@model int
@(Html.Kendo().DropDownListFor(m => m) // or m => m.ProductId if you have a more complex model
    .OptionLabel(" ")
    .DataTextField("ProductName")
    .DataValueField("ID")
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("RefDataClientSelection_Read", "RefDataClient").Type(HttpVerbs.Post); //Set the Action and Controller name
        })
        .ServerFiltering(true); //If true the DataSource will not filter the data on the client.
    })
)