[Required]
[Display(Name = "Year")]
public int Year{ get; set; }
年控制员。反恐精英
public ActionResult Index()
{
List<int> last10Years = new List<int>();
int currentYear = DateTime.Now.Year;
for (int i = currentYear - 10; i < currentYear; i++)
{
last10Years.Add(i);
}
ViewBag.LastTenYears = new SelectList(last10Years);
return View();
}
指数cshtml
@model IEnumerable<Practice.Models.YearViewModel>
<div>
<dl class="dl-horizontal">
<dt>@Html.LabelFor(m => m.Year)</dt>
<dd>@Html.DropDownList("Last Ten Years", (IEnumerable<SelectListItem>)ViewBag.LastTenYears, "Select A Year")</dd>
</dl>
</div>