2

我正在绑定到一个网格类(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();
        }       
    

但这不起作用...

4

2 回答 2

0

您只需要查看他们提供的文档:http ://demos.kendoui.c​​om/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 文件都需要绑定触发器的输入和回传。

于 2013-09-12T15:44:14.537 回答
0

我认为这会帮助你实现你所需要的 -->>

http://www.kendoui.c​​om/forums/kendo-ui-web/grid/want-to-add-dropdownlist-in-my-grid.aspx

于 2013-10-17T20:02:38.923 回答