Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC EditorTemplate with multiple inputs for the same value
    primarykey
    data
    text
    <p>I have created this editor template:</p> <pre><code>@model DateTime? @using MyMvcApp.Properties &lt;div id="dateTimePicker_@(ViewData.ModelMetadata.PropertyName)"&gt; &lt;script type="text/javascript" language="javascript"&gt; //&lt;![CDATA[ $(document).ready(function () { var $div = $('#dateTimePicker_@(ViewData.ModelMetadata.PropertyName)'); $div.find('.date').datepicker({ altFormat: 'dd-mm-yy' }); }); function clearDateTimePicker_@(ViewData.ModelMetadata.PropertyName)() { var $div = $('#dateTimePicker_@(ViewData.ModelMetadata.PropertyName)'); $div.find('.date').val(''); $div.find('.hour').val('00'); $div.find('.minute').val('00'); } //]]&gt; &lt;/script&gt; @* Date - should equal DatePicker.cshtml *@ @Html.TextBox("Value.Date", Model.HasValue ? Model.Value.Date.ToString() : string.Empty, new { @class = "date" }) &lt;img alt="@Resources.SelectDate" src="../../../images/calendar.png" class="calendarIcon" /&gt; @* Time - should equal TimePicker.cshtml *@ @Html.DropDownList("Value.Hour", new SelectList(new[] { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" }, Model.HasValue ? Model.Value.Hour.ToString("D2") : "00"), null, new { style = "width: auto; margin-left: 5px;", @class = "hour" }) : @{ List&lt;string&gt; availableMinutes = new List&lt;string&gt;(); for (int minute = 0; minute &lt; 60; minute += 1) { availableMinutes.Add(minute.ToString("D2")); } @Html.DropDownList("Value.Minute", new SelectList(availableMinutes, Model.HasValue ? Model.Value.Minute.ToString("D2") : "00"), null, new { style = "width: auto;", @class = "minute" }); } &lt;img alt="@Resources.SelectTime" src="../../../images/icon_clock_2.gif" style="margin-right: 5px" /&gt; &lt;input type="button" value="@Resources.Clear" class="ui-state-default" onclick="javascript:clearDateTimePicker_@(ViewData.ModelMetadata.PropertyName)()" /&gt; &lt;/div&gt; </code></pre> <p>As you can see, what I am trying to accomplish is that the user can enter a date/time. However, as input I want to use DateTime? (nullable) because it might be possible the user doesn't want to select ANY date/time. </p> <p>This EditorTemplate does not work when the input model is null. Is there any way to create an EditorTemplate that accepts null values and then can still fill the value if entered by the user?</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.
 

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