Note that there are some explanatory texts on larger screens.

plurals
  1. PONullable DateTime, EditorTemplates, JQ UI DatePicker
    primarykey
    data
    text
    <p>My intent was to apply the JQuery UI Datepicker to my entire site by creating an EditorTemplate as per this post <a href="http://www.dalsoft.co.uk/blog/index.php/2010/04/26/mvc-2-templates/" rel="nofollow">ASP.NET MVC 2 Templates</a></p> <pre><code>@model DateTime @{ string name = ViewData.TemplateInfo.HtmlFieldPrefix; string id = name.Replace(".", "-"); &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model) &lt;/div&gt; &lt;div class="editor-field, datepicker"&gt; @Html.EditorFor(model =&gt; model) @Html.ValidationMessageFor(model =&gt; model) &lt;/div&gt; } </code></pre> <p>The associated code works perfectly as described; however, in addition to several DateTime fields, the Model also contains 1 nullable DateTime field and navigating to the page results in this error:</p> <p><em>The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'.</em></p> <p>In fact, even creating an empty partial named "DateTime" in the path Views/Shared/EditorTemplates is enough to generate the error, suggesting that even if the template were rewritten it may still not handle a null value. The code in the Index View (generated via MvcScaffolding via EF Code-First) is the same for both nullable and non-nullable DateTime fields:</p> <pre><code> &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.ItemInstance.iArrivalDate) &lt;/div&gt; &lt;div class="editor-field,datepicker"&gt; @Html.EditorFor(model =&gt; model.ItemInstance.iArrivalDate) @Html.ValidationMessageFor(model =&gt; model.ItemInstance.iArrivalDate) &lt;/div&gt; </code></pre> <p>So is it possible to modify the template to handle the nullable DateTime?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload