Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can make an editor template like this that will make all of your date times in to datepickers.</p> <pre><code>@model DateTime @Html.TextBox("", Model.ToShortDateString(), new {type = "datetime", @class = "datepicker"}) &lt;script type="text/javascript"&gt; $(function () { $(".datepicker").datepicker({}); }); }); &lt;/script&gt; </code></pre> <p>If you do it like this then all of your textboxes tied to a DateTime object will be made in to datepickers automagically.</p> <p>You just put this in /Views/Shared/EditorTemplates and name it DateTime.cshtml</p> <p><strong>EDIT 1:</strong></p> <p>Here is how you would initialize a date time property so that you can be sure it is not null when passed. Inside your model you would declare it like this:</p> <pre><code>private DateTime _suppliedDate = DateTime.Now; public DateTime SuppliedDate { get { return _suppliedDate; } set { _suppliedDate = value; } } </code></pre> <p>In this way the date is initialized and you can still access it via the SuppliedDate property. If you have any questions about this please let me know.</p> <p><strong>EDIT 2:</strong></p> <p>I believe some additional Googling has turned up the solution to your problem I think. In the original editor template you should be able to just change @model DateTime to @model DateTime?</p> <p>The question mark makes the variable a nullable DateTime rather than a normal DateTime. If you plan to be able to leave the Date field null then you should ignore the initializer that I posted and just add the question mark. If you do not want to allow the DateTime to be null then you should use the initializer and do not add the question mark.</p> <p>Let me know if you have any questions.</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.
    1. VO
      singulars
      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