This is a migrated thread and some comments may be shown as answers.

Binding DateTimePicker to DateTimeOffset

0 Answers 160 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Hemal Shah
Top achievements
Rank 1
Hemal Shah asked on 05 Dec 2014, 09:14 PM
I have 3 date attributes defined as timestamp with timezone in Oracle database. I ise EF 5.0 and LINQ to get the data from Oracle and it works fine. I have defined the attributes in my VM As DateTimeOffset and I can populate them without any issues. However when I try to bind them to DateTimePicker in my EditorTemplate it breaks and crashes the page.

Is this not supported? If so what alternatives do I have. Does anyone have an example that I can see.

I am doing a basic MVC app using EF 5.0 and using LINQ to get the data using repository patter.

Here is a snippet of my code.

VM
[DisplayName("Activate Date")]
public DateTimeOffset? activateDate { get; set; }
 
[DisplayName("Inactivate Date")]
public DateTimeOffset? inactivateDate { get; set; }
 
[DisplayName("Energizing Date")]
public DateTimeOffset? energizingDate { get; set; }

DAO
var x = dao.CONNECTIVITY_UNIT
       .Join(dao.OP_AREA_ORG, cu => cu.OP_AREA_CODE, oa => oa.OP_AREA_CODE, (cu, oa) => new { CONNECTIVITY_UNIT = cu, OP_AREA_ORG = oa })
       .Where(w => w.CONNECTIVITY_UNIT.UNIT_TYPE.Equals("SUBSTATION"))
       .Where(w => w.CONNECTIVITY_UNIT.IS_ACTIVE_FLAG.ToUpper().Equals("Y"))
       .Where(w => w.CONNECTIVITY_UNIT.ABBR.ToUpper().Equals("BRA"))
       .Select(c => new SubstationVM
       {
          energizingDate = c.CONNECTIVITY_UNIT.ENERGIZING_DATE,
          activateDate = c.CONNECTIVITY_UNIT.ACTIVATE_DATE,
          inactivateDate = c.CONNECTIVITY_UNIT.INACTIVATE_DATE,                           
          updateTime = c.CONNECTIVITY_UNIT.UPDATE_TMSTMP
       })
       .OrderBy(o => o.substationABBR)
       .ToList();
 
return x;


View EditorTemplate
<div class="form-group">
    @Html.LabelFor(model => model.energizingDate, new { @class = "control-label col-xs-2" })
    <div class="col-xs-2">
        @Html.EditorFor(model => model.energizingDate)
        @Html.ValidationMessageFor(model => model.energizingDate)
    </div>
    <div class="col-xs-3">
        <div class="form-group">
            @Html.LabelFor(model => model.activateDate, new { @class = "control-label col-xs-4" })
            <div class="col-xs-7">
                @Html.EditorFor(model => model.activateDate)
                @Html.ValidationMessageFor(model => model.activateDate)
            </div>
        </div>
    </div>
    <div class="col-xs-3">
        <div class="form-group">
            @Html.LabelFor(model => model.inactivateDate, new { @class = "control-label col-xs-4" })
            <div class="col-xs-7">
                @Html.EditorFor(model => model.inactivateDate)
                @Html.ValidationMessageFor(model => model.inactivateDate)
            </div>
        </div>
    </div>
</div>


Am I missing anything? Is there another or better way of doing this?

Thanks for the help.

No answers yet. Maybe you can help?

Tags
Date/Time Pickers
Asked by
Hemal Shah
Top achievements
Rank 1
Share this question
or