0 Replies - 367 Views - Last Post: 10 April 2019 - 03:26 PM Rate Topic: -----

#1 Exceedinglife   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 219
  • Joined: 01-July 12

jQuery-ui datepicker asp.net mvc no value in view but textbox there is

Posted 10 April 2019 - 03:26 PM

Hey everyone,
I have a datepicker and when I donít use datepicker I get the date value in my view but with it it just displays the format MM/dd/yyyy so I am wondering how can I get my datepicker to show the saved value when I load the view. Another question I have is my datepicker DOES NOT work with [DataType(DataType.DateTime), but does with [DataType(DataType.Date), here is the code I use how can I get my values to load into the view? I also been trying to get the datetimepicker to work but no such luck.
        [Required]
        [Display(Name = "Username")]
        public string UserName { get; set; }

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

        [DataType(DataType.DateTime)]
        [Display(Name = "Date Created")]
        public DateTime DateCreated { get; set; } <script>
        $(function () {
            // DATEPICKER JQUERY ADDITION
            $(".datepicker").datepicker({
                dateFormat: "MM/dd/yy",
                changeYear: true,
                shownOn: "button"
            }).css("display", "inline-block")
                .next("button").button({
                    icons: { primary: "ui-icon-calendar" },
                    label: "Select a Date",
                    text: false
                });
            // DATETIMEPICKER JQUERY ADDITION
            $(".datetimepicker").datetimepicker({
                dateFormat: 'MM/dd/yyyy',
                timeFormat: 'hh:mm:ss',
                timeInput: true,
            });
        })
    </script> <div class="col-md-10">
                @Html.EditorFor(model => model.Birthday, new { htmlAttributes =
                 new { @class = "form-control datepicker" } })
                @Html.ValidationMessageFor(model => model.Birthday,
                 "", new { @class = "text-danger" })
            </div>



Is This A Good Question/Topic? 0
  • +

Page 1 of 1