【问题标题】:Kendo MVC DropDownListFor binding issueKendo MVC DropDownListFor 绑定问题
【发布时间】:2019-12-03 10:41:33
【问题描述】:

我是 Kendo MVC 的新手,所以请多多包涵。 我有以下代码来创建 Kendo MVC DropDownListFor:

                 @(Html.Kendo()
                    .DropDownListFor(m => m.PrimaryId.Kind)
                    .SelectedIndex(-1)
                    .OptionLabel("Choose identification kind")
                    .HtmlAttributes(new { @style = "width:100%", @required = "true" })
                    .Filter(FilterType.StartsWith)
                    .MinLength(1)
                    .DataTextField("Literal")
                    .DataValueField("Code")
                    .DataSource(source => source
                        .Read(read => read
                            .Url(AdminConfiguration.AdminAPIUrl
                                + "/classification/v1/classification-values/getClassificationValues?apiId=party&schemaId=identification-kind")
                            .Type(HttpVerbs.Get)
                        )
                        .ServerFiltering(true)
                    )
                )

ViewModel 的“PrimaryId.Kind”属性对应于“Code”属性 从 DataSource 接收到的数据 - 读取端点。

生成的输出实际上是一个下拉列表和一个选择的实际值的标签 (这让我觉得绑定出错了)。

请指教。

谢谢你, 屋大维

【问题讨论】:

    标签: asp.net-mvc razor kendo-asp.net-mvc


    【解决方案1】:

    发现问题。 这与嵌套属性用于绑定 DropDown 的事实有关。 听起来很奇怪,但我就是这样解决的:

    我为嵌套属性创建了一个属性包装器:

        public string PersonalIdKindWrapper 
        {
            get
            {
                return PrimaryId.Kind;
            }
            set
            {
                PrimaryId.Kind = value;
            }
        }
    

    然后,在视图中,我使用了 wrapper 属性:

       @(Html.Kendo()
             .DropDownListFor(m => m.PersonalIdKindWrapper)
             ………….
    

    编码愉快! :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多