Panggilan yang bagus, @airlist.
Inilah generasi bulan dan tahun di ASP.NET MVC. Tambahkan ini ke model tampilan Anda:
public IList<SelectListItem> Months = new List<SelectListItem>() {
new SelectListItem() { Text="Jan", Value="01" },
new SelectListItem() { Text="Feb", Value="02" },
new SelectListItem() { Text="Mar", Value="03" },
new SelectListItem() { Text="Apr", Value="04" },
new SelectListItem() { Text="May", Value="05" },
new SelectListItem() { Text="Jun", Value="06" },
new SelectListItem() { Text="Jul", Value="07" },
new SelectListItem() { Text="Aug", Value="08" },
new SelectListItem() { Text="Sep", Value="09" },
new SelectListItem() { Text="Oct", Value="10" },
new SelectListItem() { Text="Nov", Value="11" },
new SelectListItem() { Text="Dec", Value="12" },
};
public IEnumerable<SelectListItem> Years
{
get
{
return new SelectList(Enumerable.Range(DateTime.Today.Year, 15));
}
}
Dan ini menurut Anda:
<fieldset>
<legend>Card expiration</legend>
<div style="float: left;">
<div class="editor-label">
@Html.LabelFor(model => model.ExpirationMonth)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.ExpirationMonth, Model.Months)
@Html.ValidationMessageFor(model => model.ExpirationMonth)
</div>
</div>
<div style="float: left;">
<div class="editor-label">
@Html.LabelFor(model => model.ExpirationYear)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.ExpirationYear, Model.Years)
@Html.ValidationMessageFor(model => model.ExpirationYear)
</div>
</div>
</fieldset>