Kendo UI Drop Down 从模型加载数据
Kendo UI Drop Down loading data from model
我有一个包含产品选择的标准订单。我正在按照下面创建一个下拉列表,其中 ProductName 和 ID 是 Product 引用数据模型的属性。 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.
})
)
我有一个包含产品选择的标准订单。我正在按照下面创建一个下拉列表,其中 ProductName 和 ID 是 Product 引用数据模型的属性。 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.
})
)