【问题标题】:Kendo Grid Edit InLine model.Field(o => o.Property).Editable() depending on other PropertyKendo Grid Edit InLine model.Field(o => o.Property).Editable() 取决于其他属性
【发布时间】:2023-04-05 22:26:01
【问题描述】:

我有一个实体文档:

public class Document : EntityBase
{
    public Guid ID { get; set; }
    public string Description { get; set; }
    public string SourceLink{ get; set; }
    public bool IsFile { get; set; }
}

我正在使用 Kendo Grid 内联编辑模式。 现在我想让属性string SourceLink 可编辑,这取决于bool IsFile。 这意味着如果IsFile==falseSourceLink 应该是可编辑的。

_documentsView.cshtml:

.DataSource(dataSource => dataSource
    .Ajax()
    .Events(events => events.Error("error"))
    .Model(model =>
            {
                model.Id(o => o.ID);
                model.Field(o => o.SourceLink).DefaultValue("");
                model.Field(o => o.Description).DefaultValue("");

                if (model.Field(o => o.IsFile) == true) { 
                    model.Field(o => o.SourceLink).Editable(false)
                }
                else
                {
                    model.Field(o => o.SourceLink).Editable(true)
                }
             }
    )
    //.Create(update => update.Action("GridEditingInlineCreate", "Document", new { area = "" }))
    //.Read(...)
    //...
)

是否有可能使.Model 语句中的这个 if 语句起作用? 还是通常可以使用这种依赖的可编辑功能? 也许以另一种方式?

【问题讨论】:

  • 我想我会用两个网格绕过这个要求。一个包含 IsFile==true 的元素,第二个包含 IsFile==false 的元素。所以我可以单独处理 Editable(true/false) 选项。

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


【解决方案1】:

听起来你决定走不同的方向。您可以考虑为该列使用一个模板,该模板要么禁用该字段,要么将其写为基于IsFile 的标签。否则,我认为您无法使用当前的解决方法,因为可编辑性是在数据源上设置的,而不是在行级别。

另外一个考虑因素 - 您也许可以使用共享编辑器模板而不是编辑器来写出标签...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-27
    • 1970-01-01
    • 2015-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多