[英]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.