Episerver DateTime property without the Time!

Episerver has several built-in property types you may add to your content types, including DateTime that displays a date and time picker. Sometimes you do not want the time, only the Date!

The date and time picker looks like this:

We can fix that! Create a new editor descriptor like this:

[EditorDescriptorRegistration(TargetType = typeof(DateTime?), UIHint = "DateOnly")]
public class DateEditorDescriptor : EditorDescriptor
{
    public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable attributes)
    {
        ClientEditingClass = "dijit/form/DateTextBox";
        base.ModifyMetadata(metadata, attributes);
    }
}

Add the UIHint to your property definition, like this:

[UIHint("DateOnly")]
public virtual DateTime? StartDate { get; set; }

The date and time picker are now replaced with a date picker!

Legg igjen en kommentar

Din e-postadresse vil ikke bli publisert. Obligatoriske felt er merket med *