如果用户选择“请选择”选项,我在验证 Kendo 下拉列表时遇到问题。请让我如何触发验证
这是我到目前为止的代码:
@Html.LabelFor(model => model.ConsumerGenderID)
@(Html.Kendo().DropDownList()
.Name("Gender")
.HtmlAttributes(new { @Style = "align:center; font-size:12px; width:208px; length:35px" })
.OptionLabel("Please Select")
.Value("-1")
.DataTextField("OptionName")
.DataValueField("OptionID")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetGenderStatus", "ConsumerDetails");
});
})
)
@Html.ValidationMessageFor(model => model.GivenName1, " ")
</div>
模型
Required(ErrorMessage = "Please select a gender")]
[UIHint("GridForeignKey")]
[DisplayName("Gender")]
public int ConsumerGenderID { get; set; }
public string ConsumerGenderName { get; set;
}