Im using this guide by Stuart Leeks: ASP.NET MVC 3: Integrating with the jQuery UI date picker and adding a jQuery validate date range validator
I get this "weird" error: "The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'." ...in my create.cshtml view.
Im using a little bit different approach since I am only (for the moment) interested in getting the actual plugin to work. And also I want to be able to use the datepicker when I Create an item.
my "Speaker.cs" model:
[DataType(DataType.Date)]
[DefaultValue("00-00-00")] <- thought this might fix the "not null error", with no succes..
public DateTime ReleaseDate { get; set; }
added a partial view "Date.cshtml" under the "views/Speaker"EditorTemplates" folder.
@model DateTime
@Html.TextBox("", Model.ToString("dd/MM/yyyy"), new { @class = "date" })
my create.cshtml view
@model HiFiWarehouse.Models.Speaker
@Html.EditorFor(model => model.ReleaseDate)
added a "EditorHookup.js" in scripts folder
/// <reference path="jquery-1.5.1.js" />
/// <reference path="jquery-ui-1.8.11.js" />
$(document).ready(function () {
$(".date").datepicker({ dateFormat: "dd/mm/yy" });
});
create actions in controller
//
// GET: /Speaker/Create
[Authorize(Roles = "Administrators")
public ActionResult Create()
{
return View();
}
//
// POST: /Speaker/Create
[HttpPost]
[Authorize(Roles = "Administrators")]
public ActionResult Create(Speaker speaker)
{
if (ModelState.IsValid)
{
db.Speakers.Add(speaker);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(speaker);
}
my _Layout.cshtml header:
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/EditorHookup.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
</head>
what am I doing wrong here? :)