I’m following this tutorial to display a datepicker when I click into a textbox… But the date picker doesn’t display…
Model Class (Reservation):
[Required(ErrorMessage = "Date requise.")]
[Display(Name = "Date")]
[Column("Date")]
[DataType(DataType.DateTime)]
public DateTime Date { get; set; }
EditorHookup.js
/// <reference path="~/Scripts/jquery-1.5.1.js" />
/// <reference path="~/Scripts/jquery-ui-1.8.11.js" />
$(document).ready(function () {
$('.date').datepicker({ dateFormat: "dd/mm/yy" });
});
Partial View (Date.cshtml)
@inherits System.Web.Mvc.WebViewPage<System.DateTime?>
@model DateTime
@Html.TextBox("", Model.ToString("dd/MM/yyyy"),
new{@class="date"})
** TODO Wire up the date picker! **
My view
@model TennisOnline.Models.Reservation
@{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Create</h2>
<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-ui-1.8.11.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Content/themes/base/jquery.ui.all.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/EditorHookup.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Reservation</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Date)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Date)
@Html.ValidationMessageFor(model => model.Date)
</div>
So, do you know why the date picker doesn’t display please ? Thanks in advance
Your partial view model is not called because the DataType of your property is wrong. Replace
with
and everything should work as intended.
Edit
You should also remove the
@inheritsline from your partial view as inherits is not allowed with model.