kendoValidator and AddModelError

3 posts, 1 answers
  1. Nassouh Chehayeb
    Nassouh Chehayeb avatar
    9 posts
    Member since:
    Apr 2010

    Posted 24 Feb Link to this post


    I'm using kendoValidator to display all my validation errors with the kendo validation template. Using this:


        $(function () { $("form").kendoValidator();});


    But I have certain errors that I handle server side in the controller. Because they are kind of complex. And then I added the errors to the model this way:


    ModelState.AddModelError("Hours", "The hours and the minutes can't be both 0.");


    But if I add an error this way it is displayed with the standard ASP NET MVC way:



    <span class="field-validation-error text-danger" data-valmsg-for="Hours" data-valmsg-replace="true">The hours and the minutes can't be both 0</span>


    ¿Is some kind of way to display those errors like the kendoValidator  way?

    In the image attached I show one error client side like kendo validation and two error's server side. I would like to all of then be like the client side error.

    Thank you.

    <span class="field-validation-error text-danger" data-valmsg-for="Hours" data-valmsg-replace="true">The hours and the minutes can't be both 0.</span>

  2. Answer
    Daniel avatar
    2117 posts

    Posted 28 Feb Link to this post


    You can convert the messages via JavaScript on document ready:
    <script type="text/kendo-template" id="message">
        <span class="k-widget k-tooltip k-tooltip-validation k-invalid-msg field-validation-error" data-for="#=field#" data-valmsg-for="#=field#" id="#=field#_validationMessage">
            <span class="k-icon k-warning"> </span> #=message#
    <script type="text/javascript">
        $(function () {
            $("form").find(".field-validation-error").replaceWith(function (e) {
                var element = $(this);
                return validationMessageTmpl({ field: element.attr("data-valmsg-for"), message: element.text() });
            var validationMessageTmpl = kendo.template($("#message").html());

    The validator will not style the messages unless there is a client-side validation rule for the inputs.

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Nassouh Chehayeb
    Nassouh Chehayeb avatar
    9 posts
    Member since:
    Apr 2010

    Posted 01 Mar Link to this post

    It worked perfectly. 

    Thank you very much.

Back to Top