[英]Kendo UI add DropDownList into Grid (MVC)
我绑定到 Grid 类(UserId、FirstName、LastName、Choice)。 有谁知道如何将此代码放在 MVC 4 中 Kendo Grid 的列(选择)中:
@(Html.Kendo().DropDownList()
.Name("Test")
.DataTextField("Text")
.DataValueField("Value")
.Events(e => e.Change("change"))
.BindTo(new List<SelectListItem>()
{
new SelectListItem()
{
Text = "Option1",
Value = "1"
},
new SelectListItem()
{
Text = "Option2",
Value = "2"
}
}))
<script>
function change() {
var value = $("#Choice").val();
}
</script>
....
columns.Bound(p=> p.FirsName);
columns.Bound(p => p.LastName);
//How to Bind Choice???
我还需要后端代码中的文本(“Option1”或“Option2”)。 任何解决方案?
已编辑
我完全按照他们说的做了:
看法:
columns.Bound(p => p.Choice).ClientTemplate("#=Choice#");
控制器:
public ActionResult Index()
{
PopulateCategories();
return View();
}
.....
private void PopulateCategories()
{
var dataContext = new TestDB();
var categories = dataContext.Peoples
.Select(c => new People()
{
ChoiceID = c.ChoiceID,
Choice = c.Choice
})
.OrderBy(e => e.Choice);
ViewData["categories"] = categories;
ViewData["defaultCategory"] = categories.First();
}
但这不起作用...
你只需要看看他们提供的文档: http : //demos.kendoui.com/web/grid/editing-custom.html
它是一个自定义网格,因此也可能涉及一些 JS 更改。 您正在从您的模型进行绑定,而 kendo.js 将负责其余部分。
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ClientProductViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.ProductName);
columns.Bound(p => p.Category).ClientTemplate("#=Category.CategoryName#").Width(160);
columns.Bound(p => p.UnitPrice).Width(120);
columns.Command(command => command.Destroy()).Width(90);
})
.ToolBar(toolBar =>
{
toolBar.Create();
toolBar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Pageable()
.Sortable()
.Scrollable()
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(p => p.ProductID);
model.Field(p => p.ProductID).Editable(false);
model.Field(p => p.Category).DefaultValue(
ViewData["defaultCategory"] as Kendo.Mvc.Examples.Models.ClientCategoryViewModel);
})
.PageSize(20)
.Read(read => read.Action("EditingCustom_Read", "Grid"))
.Create(create => create.Action("EditingCustom_Create", "Grid"))
.Update(update => update.Action("EditingCustom_Update", "Grid"))
.Destroy(destroy => destroy.Action("EditingCustom_Destroy", "Grid"))
)
)
您的 csHTML 文件需要在触发器上绑定输入和回传,无论您在做什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.