【问题标题】:Kendo grid with dropdown column does not assign integer value带有下拉列的剑道网格不分配整数值
【发布时间】:2015-02-27 04:45:38
【问题描述】:

如果有人能就我的问题提出建议,我将不胜感激。 我有一个包含集合的模型:

public class Customer
{
   public Customer()
   {
       this.CustomerAddresses = new HashSet<CustomerAddress>();
   }
  //..properties
   public virtual ICollection<CustomerAddress> CustomerAddresses {get; set;}
}

在我的“创建”视图中,我有一个带有 incell 编辑的网格,它允许我存储 CustomerAddress 的集合,然后与 Customer 模型一起传递给控制器​​:

@model Customer
 //Customer inputs...

@( Html.Kendo().Grid(Model.CustomerAddresses)
    .Name("CustomerAddresses")
    .ToolBar(toolbar => { toolbar.Create(); })
    .Columns(columns =>
    {
        columns.Bound(p => p.AddressID).Hidden();       
        columns.Bound(p => p.Type)             //Foreign key of type string
               .EditorTemplateName("DropDownTemplate")
               .EditorViewData(new { ddname = "Type" })
               .ClientTemplate("#= Type #" +
        "<input type='hidden' name='CustomerAddresses[#= index(data)#].Type' value='#= Type #'  />"); 

        columns.Bound(p => p.Region)          //Foreign key of type int?
               .EditorTemplateName("DropDownTemplate")
               .EditorViewData(new { ddname = "Region" })
               .ClientTemplate("#= Region #" +
        "<input type='hidden' name='CustomerAddresses[#= index(data)#].Region' value='#= Region #'  />"); 

    })    
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .DataSource(dataSource =>
     dataSource.Ajax()
    .Model(model =>
    {
        model.Id(u => u.AddressID);

    })
    ))

下拉模板:

@if (ViewData["ddname"] == "Region")
{      
     @Html.Kendo().ComboBox().Name(ViewData["ddname"].ToString())
                  .BindTo(SelectListProvider.GetCatalog<Region>())
}
else
{   
     @Html.Kendo().ComboBox().Name(ViewData["ddname"].ToString())
                  .BindTo(SelectListProvider.GetCatalog<AddressType>())
}

问题是,当我从Region 整数列的下拉列表中选择一些项目并在单元格外按时,它不会将所选值分配给网格列。我看到一个空单元格。 但是,当我在 Type 单元格中选择字符串并按下外部时,我看到了选定的值。

我做错了什么? int 列有什么问题?

非常感谢

【问题讨论】:

    标签: jquery asp.net-mvc kendo-ui kendo-grid kendo-asp.net-mvc


    【解决方案1】:

    好吧,我终于想通了。我使用外键代替模板,以及相同列的隐藏字段:

     columns.ForeignKey(p => p.Type, someselectlist, "Value", "Text");
     columns.ForeignKey(p => p.Region, anotherselectlist, "Value", "Text");
    
     columns.Bound(p => p.Type).ClientTemplate("#= Type #" +
            "<input type='hidden' name='Addresses[#= index(data)#].Type' value='#= Type #'  />").Hidden();
     columns.Bound(p => p.Region).ClientTemplate("#= Region #" +
            "<input type='hidden' name='Addresses[#= index(data)#].Region' value='#= Region #'  />").Hidden(); 
    

    GridForeignKey.cshtml

     Html.Kendo().DropDownListFor(m => m)
            .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])
            .HtmlAttributes(new { data_value_primitive = true })
    

    现在,它可以按我的意愿工作,并且所有值都在向控制器发送。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-08
      • 1970-01-01
      相关资源
      最近更新 更多