简体   繁体   中英

Kendo ui dropdownlist validation

<%= Html.Kendo().DropDownList()
    .Name("ScheduleNumber1")
    .DataTextField("ScheduleNumber")
    .DataValueField("ScheduleNumber")
    //  .Filter("contains")
    .DataSource(source => {
        source.Read(read =>
        {
            read.Action("GetScheduleNumber1", "Ticket");
        })
        .ServerFiltering(false);
    })
    .OptionLabel("Please Select")
%>

I am using kendo dropdownlist in my asp.net mvc problem can you tell me how to add required validation when Please select is selected i am not able to find how to add validation my model validation is not working

Here is a solution to your problem, easy and straight forward. But its going bit around, eg not using the build in MVC wrapper which should do it for you.

Reality is (at least it sounds like) this functionality is not supported out of the box at the moment, which is quite a surprise.

Here is a whole thread talking about this issue, with recommended solution :

(function ($, kendo) {
    $.extend(true, kendo.ui.validator, {
        rules: {
            mvcrequired: function (input) {            
                if (input.filter("[data-val-required]").length) {
                    var value = input.val();
                    return !(value === "" || !value);
                }
                return true;
            }
        },
        messages: { 
            mvcrequired: function (input) {
                return input.attr("data-val-required");
            }
        }
    });
})(jQuery, kendo);

I am sure you had a look here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM