ValidationMessageFor不适用于Telerik?

时间:2015-04-23 14:24:21

标签: .net asp.net-mvc telerik telerik-mvc

在我的应用程序中,我尝试用Telerik ASP.NET MVC控件替换缓慢的基本HTML标记。

我使用ValidationMessageFor以防用户填写表单:

在我看来:

@using Kendo.Mvc.UI
@model DevelopmentNotesProject.Models.NoteForm
...
....
.....
    @Html.DropDownListFor(p => p.Language, new SelectList(DevelopmentNotesProject.DAL.LanguageAccess.getLanguages().OrderBy(c => c.Value), "Value", "Text"), "Select country", new { @Class = "myDropDownList" })
    @Html.ValidationMessageFor(m => m.Language)

使用注释创建的类:

   public class NoteForm
    {
        [Required]
        [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
        [Display(Name = "Title")]
        public string Title { get; set; }

        [Required]
        [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 7)]
        [Display(Name = "Text")]
        public string Text { get; set; }

        [Required]
        [Display(Name = "Language")]
        public string Language { get; set; }
    }

效果很好。 但是,当我更改代码以使用Telerik的Dropdownlist控件时:

            @(Html.Kendo().DropDownListFor(m => m.Language)
                  .Name("Language")
                  .DataTextField("Text")
                  .DataValueField("Value")
                  .BindTo((IEnumerable<SelectListItem>)ViewBag.languageslist)
                  .OptionLabel("Select a language")
            )            
            @Html.ValidationMessageFor(m => m.Language)

如果我没有在下拉列表中选择任何内容,则不会显示任何消息。 谢谢你的帮助

0 个答案:

没有答案