我很感激任何帮助。 我的模特:
public class AddressModel
{
public int AddressID { get; set; }
public string Type { get; set; }
public virtual AddressType AddressType { get; set; }
}
public class AddressType
{
public string Code{get; set;}
public string Title{get; set;}
}
我有一个带有incell编辑的网格:
@(Html.Kendo().Grid<AddressModel>(Model.Addresses)
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.Type)
.EditorTemplateName("AddressTypes");
//.ClientTemplate("#=AddressType.Title#"); //not working
})
.ToolBar(toolBar =>
{
toolBar.Create();
})
.Editable(editable => editable.Mode(GridEditMode.InCell)) =
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(p => p.AddressID);
model.Field(p => p.AddressID).Editable(false);
}))
编辑模板:
@Html.Kendo().DropDownList().Name("Type").BindTo(new SelectList(context.AddressTypes, "Code", "Title"))
问题是,当我选择某个项目时,下拉列表会显示所选值而不是文本。我需要显示Title
。我该如何解决?
答案 0 :(得分:0)
根据kendo论坛的描述。
必须绑定ViewBag,DataSource或static
public class AddressModel
{
public int AddressID { get; set; }
public string Type { get; set; }
public AddressTypeModel AddressType { get; set;}
}
public class AddressTypeModel
{
public string Code{get; set;}
public string Title{get; set;}
}
@(Html.Kendo().Grid<AddressModel>(Model.Addresses)
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.Type)
.EditorTemplateName("AddressTypesListEditor");
.ClientTemplate("#=AddressType.Title#"); //should work
})
.ToolBar(toolBar =>
{
toolBar.Create();
})
.Editable(editable => editable.Mode(GridEditMode.InCell)) =
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(p => p.AddressID);
model.Field(p => p.AddressID).Editable(false);
}))
编辑模板:
@Html.Kendo().DropDownList()
.Name("AddressType")// Name of the widget should be the same the property
.HtmlAttributes( new {@class=".k-dropdown-wrap-custom"})
.Events(e => { e.Select("AddressTypeSelected");})
.BindTo(ViewBag.AddressTypeList)
服务器端:
List<AddressTypeModel> list= _unitOfWork.AdminRepository.GetAddressTypes().Select(t =>
new AddressTypeModel
{
Code= t.Code.toString(),
FundName = t.Title.toSTring()
}).ToList();
ViewBag.AddressTypeList = list;