Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC jquery datepicker for create allow nulls
    primarykey
    data
    text
    <p>I was checking out this link:</p> <p><a href="http://blogs.msdn.com/b/stuartleeks/archive/2011/01/25/asp-net-mvc-3-integrating-with-the-jquery-ui-date-picker-and-adding-a-jquery-validate-date-range-validator.aspx" rel="nofollow">http://blogs.msdn.com/b/stuartleeks/archive/2011/01/25/asp-net-mvc-3-integrating-with-the-jquery-ui-date-picker-and-adding-a-jquery-validate-date-range-validator.aspx</a></p> <p>which describes creating a jquery datepicker for MVC for date selections in edits.</p> <p>Sure the tutorial works fine but only works for edits and not creates.</p> <p>It has a model of:</p> <pre><code>public class Foo { public string Name { get; set; } [DataType(DataType.Date)] public DateTime Date { get; set; } } </code></pre> <p>I modified its edit to create a create like:</p> <pre><code>@model DatePickerTemp.Models.FooEditModel @{ ViewBag.Title = "Create"; Layout = "~/Views/Shared/_Layout.cshtml"; } &lt;h2&gt; Create&lt;/h2&gt; @Model.Message @using (Html.BeginForm()) { @Html.EditorFor(m =&gt; m.Foo) &lt;input id="submit" name="submit" type="submit" value="Save" /&gt; } </code></pre> <p>}</p> <p>The other code uses some jquery:</p> <pre><code>$(document).ready(function () { $('.date').datepicker({dateFormat: "dd/mm/yy"}); }); </code></pre> <p>for anything with class .date:</p> <p>There is another piece of code:</p> <pre><code>@model DateTime @Html.TextBox("", Model.ToString("dd/MM/yyyy"), new { @class = "date" }) </code></pre> <p>which sets the class on the objects of type:</p> <pre><code>[DataType(DataType.Date)] </code></pre> <p>to create a jquery datepicker.</p> <p>The problem is this type is a non nullable type so when you run the create you get:</p> <pre><code>The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'. </code></pre> <p>Does anyone know how to modify the code to make the create work?</p>
    singulars
    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