I'm trying to implement an input datepicker in my asp.net-mvc project that display only years to create/edit new values of my model. I want the day and the month to be always the same (31/12/year) and allow the user to select only the year. Something like this:
In my model I have this datetime field:
[Required]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public System.DateTime MyDate{ get; set; }
I tried "{0:yyyy-31-12}" but that don't work.
And this is the Create view:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.MyDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.MyDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MyDate, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
This is my result:
I need that picker to display only years (also in edit view) and retain fixed the day and the month (12/31). Any ideas?