我正在使用的系统是一个 ASP.NET MVC 环境,带有 Jquery 用于我们的视图,我们有来自模型的验证消息设置所需的状态,然后在 html 的预期位置中有一行以呈现验证消息指定的地点,否则剑道会处理消息的隐藏/显示。然而,在查看网站的移动设备上(如果您使用开发人员工具更改网页尺寸,则在 PC 上)错误消息会在 ddl 关闭并做出有效选择时显示。
这里有一些例子:
模型中的变量:
/// <summary>
/// Department of the request
/// </summary>
[Display(Name = "Department")]
[Required(ErrorMessage = "{0} is required.")]
public string Department { get; set; }
视图中的下拉列表和验证消息:
<label class="col-sm-2 form-control-label aster">Department with Equipment issue</label>
<div class="col-sm-4">
@(Html.Kendo().DropDownListFor(m => m.RefrigerationRequest.Department)
.OptionLabel("---Select---")
.Height(450)
.HtmlAttributes(new { style = "width: 100%", id = "departmentEditor" })
.DataTextField("DepartmentDesc")
.DataValueField("DepartmentDesc")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetStoreDepartments", "MaintenanceRequests");
})
.ServerFiltering(true);
}))
@Html.ValidationMessageFor(m => m.RefrigerationRequest.Department)
</div>
一种解决方法是将字段 .Events() 添加到 kendo DDL,因为我们观察到具有此字段的 DDL(例如以下代码)没有此错误的验证状态:
<label class="col-sm-4 form-control-label aster">Equipment Type</label>
<div class="col-sm-4">
@(Html.Kendo().DropDownListFor(m => m.RefrigerationRequest.EquipmentOption.EquipmentOptionDesc)
.OptionLabel("---Select---")
.HtmlAttributes(new { style = "width: 100%", id = "equipmentOptionsEditor" })
.DataTextField("EquipmentOptionDesc")
.DataValueField("EquipmentOptionDesc")
**.Events(e => e.Change("onEquipmentOptionStatusChange"))**
.DataSource(dataSource =>
{
dataSource.Read(read => read.Action("GetEquipmentOptions","MaintenanceRequests").Data("getRefrigerationEquipmentOptionsType"));
}))
@Html.ValidationMessageFor(m => m.RefrigerationRequest.EquipmentOption.EquipmentOptionDesc)
</div>
添加此字段会导致 DDL 不按照上述方式运行,但这并不理想,因为这意味着将此修复应用于站点上的所有 DDL 并引发大量回归测试。
最后,点击DDls等页面中的其他kendo项,会导致validation message消失