嗨,任何人都可以帮助我解决我的代码问题。两天以来我一直在尝试如何在网格中添加下拉列表我正在尝试修复我的代码但我无法找出为什么下拉框没有显示在我的网格中我的代码是
<%: Html.Kendo().Grid<KendoGridAjaxEditing2.Models.ProductViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(product => product.CustomerID).Width(100);
columns.Bound(product => product.CustomerName).ClientTemplate("#=Category.CustomerFName#").Width(160);
columns.Bound(product => product.CustomerLastName);
columns.Bound(product => product.Customerage).Width(250);
columns.Command(commands =>
{
commands.Edit(); // The "edit" command will edit and update data items
commands.Destroy(); // The "destroy" command removes data items
}).Title("Commands").Width(200);
})
.ToolBar(toolbar => toolbar.Create()) // The "create" command adds new data items
.Editable(editable => editable.Mode(GridEditMode.InLine)) // Use inline editing mode
.DataSource(dataSource =>
dataSource.Ajax()
.Model(model =>
{
model.Id(product => product.CustomerID); // Specify the property which is the unique identifier of the model
model.Field(product => product.CustomerID).Editable(false); // Make the ProductID property not editable
model.Field(p => p.Category).DefaultValue(
ViewData["defaultCategory"] as KendoGridAjaxEditing2.Models.ClientCategoryViewModel);
})
.Create(create => create.Action("Products_Create", "Home")) // Action invoked when the user saves a new data item
.Read(read => read.Action("Products_Read", "Home")) // Action invoked when the grid needs data
.Update(update => update.Action("Products_Update", "Home")) // Action invoked when the user saves an updated data item
.Destroy(destroy => destroy.Action("Products_Destroy", "Home")) // Action invoked when the user removes a data item
)
.Pageable()
%>
和 HomeController 方法
private void PopulateCategories()
{
var dataContext = new NorthwindEntities();
var categories = dataContext.Customer_details
.Select(c => new ClientCategoryViewModel
{
ID = c.ID,
CustomerFName = c.name
})
.OrderBy(e => e.CustomerFName);
ViewData["categories"] = categories;
ViewData["defaultCategory"] = categories.First();
}
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
PopulateCategories();
return View();
}
和我的 ClientCategoryViewModel 类
public class ClientCategoryViewModel
{
public int ID { get; set; }
public string CustomerFName { get; set; }
}
当我尝试 .ClientTemplate("#=Category.CustomerFName#").Width(160); 在我看来,我没有得到任何结果,但是一旦我将其删除,我的网格就会显示记录,但我无法理解为什么我的网格中没有出现下拉菜单,并且我在过去 2 到 3 天尝试这样做,但我无法找出解决方案我试图将此链接视为指南http ://demos.kendoui.com/web/grid/editing.html但问题仍然存在请有人帮助我谢谢