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

后端 未结 9 878
执念已碎
执念已碎 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:34

    Attempting to provide a concise update, based on Enzero's answer.

    • Install the Bootstrap.Datepicker package.

      PM> install-package Bootstrap.Datepicker
      ...
      Successfully installed 'Bootstrap.Datepicker 1.7.1' to ...
      
    • In AppStart/BundleConfig.cs, add the related scripts and styles in the bundles.

      bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
            //...,
            "~/Scripts/bootstrap-datepicker.js",
            "~/Scripts/locales/bootstrap-datepicker.YOUR-LOCALE-CODE-HERE.min.js"));
      
      bundles.Add(new StyleBundle("~/Content/css").Include(
            ...,
            "~/Content/bootstrap-datepicker3.css"));
      
    • In the related view, in the scripts' section, enable and customize datepicker.

      @section scripts{
          
      
    • Eventually add the datepicker class in the related control. For instance, in a TextBox and for a date format in the like of "31/12/2018" this would be:

      @Html.TextBox("YOUR-STRING-FOR-THE-DATE", "{0:dd/MM/yyyy}", new { @class = "datepicker" })
      

提交回复
热议问题