0

This is an Asp.net MVC application. I have installed packages jQuery.alidation.Globalize and jQuery.UI.i18n and have set fixed culture "es-PY" in web.config

<globalization enableClientBasedCulture="true" uiCulture="es" culture="es-PY" />

I have set this culture also for jQuery validations:

$(document).ready(function () {
    Globalize.culture('es-PY');
    $.datepicker.setDefaults($.datepicker.regional["es"]);
    $("input[type='date']").datepicker();
});

Also i have decorated Dates properties as follow in my model:

[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public System.DateTime Fecha { get; set; }

I'm facing problems with displaying the jQuery datepicker, as you can see from the image i get not one, but two dropdown calendars, apart from that in the text input the value is seted to dd/mm/aaaa, it should be rendered with the Fecha property. When i try to select a date from the calendar the client validation fails which is disconcerting me because es-PY culture accept dd/MM/yyyy date format.

So my question actually are two in one: Why i am getting two calendars for the inputbox and what else should i do to get the date pass validation in client browser?

enter image description here

7
  • 1
    Did you use EditorFor? If you have an email control template, it will use that as the editor, and then you applied another using the datepicker plugin. Commented Jun 13, 2014 at 22:14
  • @TiesonT. Yes I use editor for, I dont get you when you say an email control template? Commented Jun 13, 2014 at 22:21
  • 1
    possible duplicate of Format Date with culture in Razor @Html.EditFor Commented Jun 13, 2014 at 22:21
  • 1
    @Elio.Batista If you want to use the datepicker plugin, change EditorFor to TextBoxFor - otherwise the Razor engine will create a <input type="date" /> element, and then it's up to the browser to decide what to do. Commented Jun 13, 2014 at 22:37
  • 1
    @Elio.Batista Sorry, the "email" bit was me not paying attention to what I was typing; that should have read "a date control template". For instance, I use Telerik UI controls, and one of the things they add is an EditorTemplate folder in Shared. That means a DateTime property triggers the Razor engine to use Telerik's Date.cshtml template when using EditorFor. Commented Jun 13, 2014 at 22:41

1 Answer 1

2

If you want to use the datepicker plugin, change EditorFor to TextBoxFor - otherwise the Razor engine will create a <input type="date" /> element, and then it's up to the browser to decide what to do.

For instance, I use Telerik UI controls, and one of the things they add is an EditorTemplate folder in Shared. That means a DateTime property triggers the Razor engine to use Telerik's DateTime.cshtml or Date.cshtml (depending on the data-annotated type) template when using EditorFor.

The same would be true if you had any property that mapped to the name of an editor template.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.