解决了:我所做的就是将DataTextField和DataValueField更改为"Type",当我返回.val()时,它给了我与文本完全相同的字段.
我试图从使用脚本的Kendo下拉列表的选定索引的视图中向Controller返回一个值.到目前为止,我只能让它返回索引值而不是文本.
边问题:另外,在当前上下文中,distinct不起作用,如果我从视图中删除.DataValueField以及从我的DTO和Controller中取出Product ID,我可以得到.DataTextField的不同值("Type" ).
主要问题:是名称:$("#typeDropDownList").val() 只抓取ProductID(就像它应该)并且如果我尝试使用.text()来抓取它,而不是它给了我一个""(空白字符串)每次都是结果.我想知道如何只抓取下拉列表的文本值.
它也将更新Kendo Grid.
我是一个相当陌生的编程人员,而且我正处于工作阶段,请放轻松.
这是我的观点
<h2>Products</h2>
@(Html.Kendo().DropDownList()
.Name("typeDropDownList")
.HtmlAttributes(new { style = "width: 250px" })
.DataTextField("Type")
.DataValueField("ProductID")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetList", "AdvSlider")
.Data("refresh");
})
.ServerFiltering(true);
})
.OptionLabel("Select a type")
.Events(e => e.Change(
@<text>
function(e){
$("#grid").data("kendoGrid").dataSource.read();
}</text>
))
)
@(Html.Kendo().Grid<SKLiqPOC.Models.PatDTO>()
.Name("grid")
.DataSource(dataSource => dataSource // Configure the grid data source
.Ajax() // Specify that ajax binding is used
.ServerOperation(false)
.Read(read => read.Action("GetJson", "AdvSlider")
.Data("refresh"))
// Set the action …Run Code Online (Sandbox Code Playgroud)