我正在绑定到一个网格类(UserId、FirstName、LastName、Choice)。有谁知道如何将此代码放在 MVC 4 中剑道网格的列(选择)中:
@(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();
}
但这不起作用...