In my previous version, I used a Date Picker which could default as null as follows;
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime?>" %>
<%:Html.TextBox("", (Model.HasValue ? Model.Value.ToShortDateString() : string.Empty), new { @class = "datePicker" }) %>
Now I am using
@model DateTime?
@Html.TextBox("", (Model.HasValue ? Model.Value.ToShortDateString() : string.Empty), new { @class = "datePicker" }))
And this doesn’t work.
When I click on a Date Field, I do not get a popup anymore.
So a date field looks like;
@Html.EditorFor(model => model.contract.GivenDate)
This is a DateTime field.
In my _Layout I have;
$(function () {
$(“.datePicker”).datepicker({ showOn: ‘both’, dateFormat: ‘dd/mm/yy’ });
});
Also I reference;
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.4.custom.min.js")" type="text/javascript"></script>
So what am I doing wrong?
The following works for me:
Inside
Views\Home\Index.cshtml:Inside
Views\Shared\EditorTemplates\DateTime.cshtml:And finally
Models\FooBar.cs:Can you try this out to see if there’s any differences?