jQuery datepicker altFormat not displayed

前端 未结 2 638
野趣味
野趣味 2021-01-27 09:31

I have a jQuery datepicker that is localized based on the language preferences of the seller. Each datepicker customization has a different date format but I want the input whe

2条回答
  •  野性不改
    2021-01-27 10:25

    Good point, SirDerpington,

    however I could not find a fully functional MVC solution for this. The idea was to use altFormat for actual data submitting and dateFormat - just for displaying (taking into consideration UI culture or just a predefined format one likes).

    Finally I have my solution, here it is (alas, based on name conventions so far):

    @model System.DateTime ?
    @Html.Hidden("", Model.HasValue ? string.Format("{0:yyyy-MM-dd}", Model.Value) : string.Empty)
    @Html.TextBox("", Model.HasValue ? string.Format("{0:dd.MM.yyyy}", Model.Value) : string.Empty, new { @class = "date", Id = "DatePicker" + ViewData.ModelMetadata.PropertyName, Name = "DatePicker" + ViewData.ModelMetadata.PropertyName })
    
    
    
    [MetadataType(typeof(EmployeeMetadata))]
    public partial class Employee
    {
    }
    
    class EmployeeMetadata
    {
        [DataType(DataType.MultilineText)]
        public string Description { get; set; }
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        [Display(Name = "Employment Date")]
        public Nullable EmploymentDate { get; set; }
    }
    

    UPD: I have now installed Globalize to simplify the things. But I still cannot make it work as expected. The matter is Globalize ALREADY contains all culture settings. But seems like DatePicker requires a separate "per culture" regional file (with arrays of culture settings), that, in fact, contains the same settings as Globalize! It's silly! Global culture settings should be the same for all controls! I still cannot believe I would have to look for specific culture datepicker files and make this duplication... :(

提交回复
热议问题