i using editorfor on list of componentparameter
s (shown below). editor template switches based on value, , datetime isn't working. when @ html before postback, values there, in list<componentparameter>
inside model, spots corresponding datetimes null.
public class componentparameter { public string value { get; set; } public string description { get; set; } public string type { get; set; } public bool optional { get; set; } }
editortemplate:
@switch (model.type.tolowerinvariant()) { case "datetime": html.renderpartial("parameterheader", model); <div class="grid_4"> @{ datetime value; if (!datetime.tryparse(model.value, out value)) { value = datetime.today + timespan.fromhours(6); } } // commenting out next 2 lines causes value post <div class="grid_9">@html.textbox("", value.tostring("mm/d/yyyy"), new { @class = "date-picker autotooltip " + model.requiredclass, @data_mwtooltip = model.description })</div> @html.textbox("", value.tostring("hh:mm tt"), new {@class="time-picker"}) @html.hiddenfor(x => x.value, new { @class = "input-time-picker" }) @html.hiddenfor(x => x.optional) @html.hiddenfor(x => x.description) @html.hiddenfor(x => x.type) </div> break; case "string": <div class="grid_12"> @{ html.renderpartial("parameterheader", @model); } @html.textboxfor(x => x.value, new { @class = "autotooltip " + model.requiredclass, @data_mwtooltip = model.description }) @html.hiddenfor(x => x.optional) @html.hiddenfor(x => x.description) @html.hiddenfor(x => x.type) </div> break; }
html:
<div class="grid_4"> <div class="grid_9"> <span class="ui-spinner ui-widget ui-widget-content ui-corner-all"> <input id="componentlist_0__componentparameterlist_0_" class="time-picker ui-spinner-input valid" type="text" value="06:00 am" name="componentlist[0].componentparameterlist[0]" aria-valuenow="1357041600000" autocomplete="off" role="spinbutton"> <a class="ui-spinner-button ui-spinner-up ui-corner-tr ui-button ui-widget ui-state-default ui-button-text-only" tabindex="-1" role="button" aria-disabled="false"> <a class="ui-spinner-button ui-spinner-down ui-corner-br ui-button ui-widget ui-state-default ui-button-text-only" tabindex="-1" role="button" aria-disabled="false"> </span> <input id="componentlist_0__componentparameterlist_0__value" class="input-time-picker" type="hidden" value="07/11/2013 06:00 am" name="componentlist[0].componentparameterlist[0].value"> <input id="componentlist_0__componentparameterlist_0__optional" type="hidden" value="false" name="componentlist[0].componentparameterlist[0].optional"> <input id="componentlist_0__componentparameterlist_0__description" type="hidden" value="start time" name="componentlist[0].componentparameterlist[0].description"> <input id="componentlist_0__componentparameterlist_0__type" type="hidden" value="datetime" name="componentlist[0].componentparameterlist[0].type"> </div> <div class="grid_12"> <label> <input id="componentlist_0__componentparameterlist_5__value" class="autotooltip paramrequired required" type="text" value="" name="componentlist[0].componentparameterlist[5].value" data-mwtooltip="attention line" title=""> <input id="componentlist_0__componentparameterlist_5__optional" type="hidden" value="false" name="componentlist[0].componentparameterlist[5].optional"> <input id="componentlist_0__componentparameterlist_5__description" type="hidden" value="attention line" name="componentlist[0].componentparameterlist[5].description"> <input id="componentlist_0__componentparameterlist_5__type" type="hidden" value="string" name="componentlist[0].componentparameterlist[5].type"> </div>
looking @ html again, issue html helpers trying bind model well, evidenced id="componentlist_0__componentparameterlist_0_"
. seemed cause model not bind @ all, due errors.
since trying input fields work with, removed , replaced them regular html <input>
.
Comments
Post a Comment