// GET: /Home/AddVehicle public ActionResult AddVehicle() { // Attention - Create and configure a view model object var form = new VehicleAddForm(); form.ModelYear = DateTime.Now.Year; // this.Manufacturers is a // collection of Manufacturer objects form.ManufacturerList = new SelectList(this.Manufacturers, "Id", "Name"); // this.Classifications is a // collection of string objects // Notice that we use the simple constructor // When the Razor view engine creates the HTML item-selection element, // it will not create a "value" attribute // The result will be that the visible text will be submitted // as the value of the name-value pair form.ClassificationList = new SelectList(this.Classifications); return View(form); }
// GET: /Home/AddVehicle public ActionResult AddVehicle() { // Attention - Create and configure a view model object var form = new VehicleAddForm(); form.ModelYear = DateTime.Now.Year; // this.Manufacturers is a // collection of Manufacturer objects form.ManufacturerList = new SelectList(this.Manufacturers, "Id", "Name"); // this.Classifications is a // collection of string objects // Notice that we use the simple constructor // When the Razor view engine creates the HTML item-selection element, // it will not create a "value" attribute // The result will be that the visible text will be submitted // as the value of the name-value pair form.ClassificationList = new SelectList(this.Classifications); return(View(form)); }