【问题标题】:Kendo UI MVC grid popup mode insert mode model.set not working for DropDownListKendo UI MVC 网格弹出模式插入模式 model.set 不适用于 DropDownList
【发布时间】:2016-04-01 20:17:01
【问题描述】:

我有一个这样的样本popup editing mode

我想在第一次插入时存储我的模型,并设置默认值。

@(Html.Kendo().Grid<License>()
      .Name("popupGrid")
      .Columns(columns =>
      {
          columns.Bound(p => p.LicenseId).Width(20).Hidden().HeaderHtmlAttributes(new { @title = "License" });
          columns.ForeignKey(p => p.CustomerId, (System.Collections.IEnumerable)ViewData["customers"], "CustomerID", "CustomerName")
            .Title("Customer").Width(200);
          columns.Bound(p => p.VendorId).Width(20).HeaderHtmlAttributes(new { @title = "Vendor" });
          columns.Bound(p => p.ProductId).Width(20).HeaderHtmlAttributes(new { @title = "Product" });
          columns.Command(p => p.Edit().Text("Edit").HtmlAttributes(new { @title = "Edit" })).Width(80);
      })
          .ToolBar(toolbar => toolbar.Create().HtmlAttributes(new {@id ="MyAddButton" ,@title = "Add" }))
      .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("PopupEditView"))
                  .Events(e => e.Edit("onGridEdit").Save("onGridSave"))
      .DataSource(dataSource => dataSource
          .Ajax()
          .Model(model => model.Id(p => p.LicenseId))
              .Create(create => create.Action("Create", "Home").Type(HttpVerbs.Post))
              .Read(read => read.Action("Read", "Home").Type(HttpVerbs.Post))
              .Update(update => update.Action("Update", "Home").Type(HttpVerbs.Post))
          )
)

<script>   
        var myModel;
        function onGridSave(e) {
            if (e.model.isNew()) {
                myModel = e.model;
            }
        }   
        function onGridEdit(e) {
            if (e.model.isNew()&&myModel!=null) {
                e.model.set("CustomerId", myModel.CustomerId);
                e.model.set("VendorId", myModel.VendorId);
                e.model.set("ProductId", myModel.ProductId);
            }
        }
</script>

但它不起作用。

以下代码也不起作用:

$(e.container).find('input[name="CustomerId"]').data("kendoDropDownList").value(myModel.CustomerId);//it's not giving error. but CustomerId is null in model of create method

其实我想this。但我不知道如何在防止关闭窗口的同时更新数据源。

【问题讨论】:

    标签: c# kendo-ui telerik kendo-grid kendo-asp.net-mvc


    【解决方案1】:

    您可以尝试使用valuePrimitive: true 配置您的下拉列表

    http://docs.telerik.com/kendo-ui/api/javascript/ui/dropdownlist#configuration-valuePrimitive

    【讨论】:

    • 我试过了,但不幸的是它没有用@Adam。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-01
    • 1970-01-01
    • 2013-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多