views:

37

answers:

1

Using EF-generated classes, here's my metadata class:

    [DisplayName("Approved Date")]
    [DataType(DataType.DateTime)]
    [DisplayFormat(ApplyFormatInEditMode = true,
                            HtmlEncode = false,
                            NullDisplayText = "", 
                            DataFormatString = "{0:MM/dd/yyyy}")]
    public object ApprovedDate{ get; set; }

The view:

<%: Html.EditorFor(model => model.Standard)%>

The editor:

<%:Html.EditorFor(model => model.ApprovedDate)%>

The DateTime.ascx:

<%string name = ViewData.TemplateInfo.HtmlFieldPrefix;%>
<%string id = name.Replace(".", "_");%>

<div class="clear">
    <div class="editor-label"><%:Html.LabelFor(model => model)%></div>
    <div class="editor-field">
        <%:Html.TextBoxFor(model => model)%>
        <%= Html.ValidationMessageFor(model => model)%>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function () {

        $("#<%=id%>").datepicker({
            showOn: 'both',
            dateFormat: 'm/d/yy',
            changeMonth: true,
            changeYear: true
        });
    });
</script>

Nothing seems to work. I have to maintain the binding, so I don't want to do raw HTML.

All the date fields output with the same formatting, which includes the Time.

3/12/2009 12:00:00AM

What it needs to be is

3/12/2009

Thanks!

+1  A: 

I ended up using <%= Html.TextBox(null, string.Format("{0:d}", Model))%> . Seems to work, and retains the bindings.

morganpdx