I am creating a Trailer for existing Driver (that can be selected from Drop Down list).
@Html.DropDownListFor(x => x.Driver.driverID, (SelectList)ViewBag.DriverID, "-- Please Select -- ", new { @class = "form-control" })
For CREATE function it works perfectly.
//Create Get
public ActionResult Create()
{
ViewBag.DriverID = new SelectList(db.Drivers, "driverID", "driverFullName");
return View();
}
For EDIT function (edit trailers number and leave the driver NULL) it does not work.
//Edit Get
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Trailer trailer = db.Trailers.Find(id);
if (trailer == null)
{
return HttpNotFound();
}
ViewBag.DriverID = new SelectList(db.Drivers.ToList(), "driverID", "driverFullName");
return View(trailer);
}
I have the -- Please Select -- on the drop down list as a first empty value.
How could I put a NULL value on this first empty value (so the trailer would have NO driver selected) from drop down list?
null?