剑道UI模型验证只在本地环境下工作

Kendo UI Model validation only working on local environment

本文关键字:环境 工作 UI 模型 验证 剑道      更新时间:2023-09-26

我正在使用剑道UI与ASP。asp.net MVC 3。我们有一个页面,我们使用MVC包装器的剑道网格,绑定到模型类注释验证需求。

在本地部署时一切正常,但在我们的测试服务器上部署时,验证不起作用。经过仔细检查,我发现Kendo MVC包装器为列定义生成的javascript结果对每个列的"editor"字段具有不同的值。

在我们的测试服务器上运行时,"editor"字段的值缺少输入元素的data-val属性。

产生这种差异的原因是什么?我们已经仔细检查过了,这两个部署使用的是同一个源。此外,在测试环境中,其他一切都正常工作。

这是本地部署时其中一列上的"editor"字段的值:

"editor":"'u003cinput class='"text-box single-line'" data-val='"true'" data-val-regex='"Invalid Platform Name!'" data-val-regex-pattern='"^[a-z A-Z]+$'" data-val-required='"The PlatformName field is required.'" id='"PlatformName'" name='"PlatformName'" type='"text'" value='"'" /'u003e'u003cspan class='"field-validation-valid'" data-valmsg-for='"PlatformName'" data-valmsg-replace='"true'"'u003e'u003c/span'u003e"

下面是测试服务器上为同一列生成的内容:

"editor":"'u003cinput class='"text-box single-line'" id='"PlatformName'" name='"PlatformName'" type='"text'" value='"'" /'u003e'u003cspan class='"field-validation-valid'" id='"PlatformName_validationMessage'"'u003e'u003c/span'u003e"

模型:

public class PlatformModel
{
    public int Id { get; set; }
    [Required]
    [RegularExpression(@"^[a-z A-Z]+$", ErrorMessage = "Invalid Platform Name!")]
    [CustomValidation(typeof(ApproverGroupValidator), "IsEntryNull")]
    public string PlatformName { get; set; }
    [Required]
    public string AclGroup { get; set; }
    [Editable(false)]
    public bool IsDefault { get; set; }
}
MVC包装:

@(Html.Kendo().Grid<PlatformModel>().Name("ManagePlatformGrid")
            .Columns(columns =>
            {
                columns.Bound(c => c.Id).Hidden();
                columns.Template(@<img />).ClientTemplate("# if(!IsDefault) { #<div class='btnGridDelete' onclick='"deleteRow(this, 'ManagePlatformGrid', 'Platform', 'DeletePopoutPF')'"><span>X</span></div># } #")
                    .Width(30)
                    .HeaderHtmlAttributes(new { style = "border-left-width:0px;border-right-width:0px;" })
                    .HtmlAttributes(new { style = "border-left-width:0px;" });
                columns.Bound(c => c.PlatformName).Title("Platform Name")
                    .HeaderHtmlAttributes(new { style = "border-left-width:0px;" })
                    .HtmlAttributes(new { style = "border-left-width:0px;text-align:right;" })
                    .Width(160);
                columns.Bound(c => c.AclGroup).Title("ACL Group");
            })
            .Sortable()
            .Editable(editable => editable.Mode(GridEditMode.InCell).CreateAt(GridInsertRowPosition.Bottom))
            .Events(events => events.DataBound("PlatformBound"))
            .DataSource(dataSource => dataSource
                .Ajax()
                .Batch(true)
                    .Read(read => read.Action("GetPlatform", "ApproverGroupTeam"))
                    .Model(model => model.Id(c => c.Id))
                    .Create(create => create.Action("CreatePlatform", "ApproverGroupTeam"))
                    .Update(update => update.Action("UpdatePlatform", "ApproverGroupTeam"))
                    .Destroy(create => create.Action("DeletePlatform", "ApproverGroupTeam"))
                    .Events(events => events.Error("PlatformHaveErrors"))
            )
        )

问题是我们使用的是Web。配置转换和缺少两行:

<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />

在我们的Web. test .config文件中,所以即使它们出现在主Web中。在我们的测试环境中,appSettings部分被缺少这些设置的部分所替换。