How to add Date Picker Bootstrap 3 on MVC 5 project using the Razor engine?

后端 未结 9 892
执念已碎
执念已碎 2020-11-28 20:13

I need some guide lines on how to install a Date Picker Bootstrap 3 on a MVC 5 project using the Razor engine. I found this link here but couldn\'t make it work in VS2013. <

9条回答
  •  盖世英雄少女心
    2020-11-28 20:29

    [DataType(DataType.Date)]
    public DateTime BirthDate { get; set; }
    

    decorate your model like this. can use a bootstrap date time picker I used this one. https://github.com/Eonasdan/bootstrap-datetimepicker/

    I suppose you already have bundles for bootstrap css and js

    Your date picker bundle entries

     bundles.Add(new ScriptBundle("~/bundles/datePicker").Include(
               "~/Scripts/moment.min.js",
               "~/Scripts/bootstrap-datetimepicker.min.js"));
    
            bundles.Add(new StyleBundle("~/Content/datepicker").Include(
                     "~/Content/bootstrap-datetimepicker.min.css"));
    

    Render bundles on your Layout View

    @Styles.Render("~/Content/datepicker")
    @Scripts.Render("~/bundles/datePicker")
    

    Your HTML in view

    @Html.LabelFor(model => model.BirthDate, htmlAttributes: new { @class = "lead col-md-2" })
    @Html.TextBoxFor(model => model.BirthDate, new { @class = "datetimepicker form-control" }) @Html.ValidationMessageFor(model => model.BirthDate, "", new { @class = "text-danger" })

    At the end of your view add this.

    
    

提交回复
热议问题