ASP.NET MVC 4 does not work with jquery datepicker -
i'm beginner of asp.net jquery , html5 , i'm developing asp.net mvc 4 site have form 2 date fields. don't want insert date manually, tried use solution implement simple datepicker:
<fieldset> <legend>rangedateviewmodel</legend> <div class="editor-label"> start date </div> <div class="editor-field"> @html.textboxfor(model => model.startdate, new{ @class = "date" }) @html.validationmessagefor(model => model.startdate) </div> <div class="editor-label"> end date </div> <div class="editor-field"> @html.textboxfor(model => model.enddate, new{ @class = "date" }) @html.validationmessagefor(model => model.enddate) </div> <p> <input type="submit" value="create" /> </p> </fieldset> } <div> @html.actionlink("back list", "index") </div> @section scripts { @scripts.render("~/bundles/jqueryval") @scripts.render("~/bundles/jqueryui") @styles.render("~/content/themes/base/css") <script src="@url.content("~/scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@url.content("~/scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> <script src="@url.content("~/scripts/jquery-1.5.1.min.js")" type="text/javascript"></script> <script src="@url.content("~/scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $(".date").datepicker(); }); </script> }
the code works good, if select date 13th until 30/31 th of month have same warning: "the field startdate must date." , "the field enddate must date."
edit: add viewmodel asked:
public class rangedateviewmodel { public datetime startdate { get; set; } public datetime enddate { get; set; } }
you need tell datepicker aren't using month first date format:
$.datepicker.setdefaults({ dateformat: "dd/mm/yy" });
however, not big part of problem (and depending upon browser culture, date picker using day first date format).
there issues day first date formats , jquery validation, mvc binding. 1 of main reasons stick year first date format (yyyy-mm-dd), since parsed correctly various libraries.
Comments
Post a Comment