C# telerik razor控件中弹出窗口中的编辑下拉列表问题
我已经在Telerik Razor Control中创建了dropdownlist。现在的问题是,当我点击编辑按钮gridview时,会出现一个弹出窗口,我得到的dropdownlist充满了值..bt我没有得到选中的dropdownlist值。。。我的意思是,我没有得到所选记录的特定值。它给出了dropdownlist中的所有值,就像我们在单击“添加”按钮时得到的值一样。因此,请任何人帮我解决这个问题。我知道这个答案晚了一年,但我还是会发布它。 对于MVC:在网格中,使用foreigkey为字段定义dropdownlist,如下所示:C# telerik razor控件中弹出窗口中的编辑下拉列表问题,c#,telerik,C#,Telerik,我已经在Telerik Razor Control中创建了dropdownlist。现在的问题是,当我点击编辑按钮gridview时,会出现一个弹出窗口,我得到的dropdownlist充满了值..bt我没有得到选中的dropdownlist值。。。我的意思是,我没有得到所选记录的特定值。它给出了dropdownlist中的所有值,就像我们在单击“添加”按钮时得到的值一样。因此,请任何人帮我解决这个问题。我知道这个答案晚了一年,但我还是会发布它。 对于MVC:在网格中,使用foreigkey为字
@(Html.Kendo().Grid<YOURModel>()
.Name("yournameGrid")
.Columns(columns =>
{
columns.Bound(device => device.Id),
columns.ForeignKey(model => model.HeadSetId, (System.Collections.IEnumerable)ViewData["headsets"], "Id", "Name");
})
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(device => device.Id);
model.Field(d => d.HeadSetId).DefaultValue(ViewData["defaultHeadSetId"]);
})
.Read(read => read.Action("FunctionHere", "ControllerHere"))
)
此函数的外观如下所示:
private void PopulateDropdownList()
{
var data= db.HeadSets.ToList()
.OrderBy(h => h.Name)
.Select(h => new HeadSet
{
Id = h.Id,
Name = h.Name
});
ViewData["headsets"] = headSets;
int hsID = 0;
if (headSets.Count() > 0)
{
hsID = headSets.First().Id;
}
ViewData["defaultHeadSetId"] = hsID;
}
在弹出窗口(模板)中定义下拉列表:
@(Html.Kendo().DropDownListFor(m => m.HeadsetId)
.Name("HeadSetId") // THE NAME OF THE WIDGET MUST BE THE SAME AS THE PROPERTY!.
.HtmlAttributes(new { @style = "margin-left:15px;" })
.DataValueField("Id") // The value of the dropdown is taken from the item's Id property.
.DataTextField("Name") // The text of the items is taken from the item's Name property.
.BindTo((System.Collections.IEnumerable)ViewData["headsets"])// A list of all headsets which is populated in the controller.
)
这将正确地将记录的选定值绑定到dropdownlist。您能更具体一点吗?您是否使用Telerik的组合框和网格控件来实现ASP.NET MVC?也许如果您提供一些代码,我们可以更好地帮助您解决问题。
@(Html.Kendo().DropDownListFor(m => m.HeadsetId)
.Name("HeadSetId") // THE NAME OF THE WIDGET MUST BE THE SAME AS THE PROPERTY!.
.HtmlAttributes(new { @style = "margin-left:15px;" })
.DataValueField("Id") // The value of the dropdown is taken from the item's Id property.
.DataTextField("Name") // The text of the items is taken from the item's Name property.
.BindTo((System.Collections.IEnumerable)ViewData["headsets"])// A list of all headsets which is populated in the controller.
)