DatePicker validation message - data-val-date

3 posts, 1 answers
  1. Jiri
    Jiri avatar
    7 posts
    Member since:
    Mar 2016

    Posted 20 Jul 2016 Link to this post


    I have a problem  with validation message for DatePicker in UI for ASP.NET MVC. 

    Property in model:

    [DataType(DataType.Date, ErrorMessage = "Please enter a valid date. - TEST")]
    public DateTime FromDateTime { get; set; }

    Part of my cshtml file:

    @(Html.Kendo().DatePickerFor(model => model.Filter.FromDateTime)
    .HtmlAttributes(new {@class = "form-control", style = "width: 100%"})
    @Html.ValidationMessageFor(model => model.Filter.FromDateTime, "", new { @class = "text-danger" })

    This is part of the html page which is generated from the cshtml file:

    <input name="Filter.FromDateTime" class="form-control k-input input-validation-error" id="Filter_FromDateTime" role="combobox" aria-disabled="false" aria-expanded="false" aria-invalid="true" aria-required="true" aria-describedby="Filter_FromDateTime-error" aria-owns="Filter_FromDateTime_dateview" style="width: 100%;" type="text" value="20. 4. 2016" data-val-required="Toto datum musí být vyplněno." data-val-date="The field FromDateTime must be a date." data-val="true" data-role="datepicker">

    Image of the part of the html page from webbrowser is in file "datepickerError.png".

    The problem is in the content of the validation message. Message in my model is "Please enter a valid date. - TEST" but message in html is "The field FromDateTime must be a date." 

    I want to create localization of this message and change its content. How can I do it?

    Thank you for your advice.






  2. Answer
    Daniel avatar
    2231 posts

    Posted 22 Jul 2016 Link to this post


    The date validation is generated implicitly by MVC and the message does not depend on the DataType attribute. It is possible to use the approach demonstrated in this blog post to localize the messages for dates and numbers. 

    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Jiri
    Jiri avatar
    7 posts
    Member since:
    Mar 2016

    Posted 22 Jul 2016 Link to this post

    Thank you very much.
Back to Top