You could pass the selected value as 4th argument of the SelectList constructor:
var query = newdb.Incident.Select(c => new { c.ID, c.Name });
ViewBag.items = new SelectList(query.AsEnumerable(), "ID", "Name", "4");
and also in your view make sure that you are using a different value as first argument to the DropDownList helper because right now you are using "items"
which is wrong, because the first argument represents the name of the generated dropdownlist that will be used back in the controller to fetch the selected value:
@Html.DropDownList(
"selectedIncidentId",
(SelectList) ViewBag.items,
"--Select a Incident--"
)
Also I would recommend you using view models and the strongly typed version of the DropDownListFor helper:
public class IncidentsViewModel
{
public int? SelectedIncidentId { get; set; }
public IEnumerable<SelectListItem> Incidents { get; set; }
}
and then:
public ActionResult Foo()
{
var incidents = newdb.Incident.ToList().Select(c => new SelectListItem
{
Value = c.ID.ToString(),
Text = c.Name
});
var model = new IncidentsViewModel
{
SelectedIncidentId = 4,
Incidents = incidents
}
return View(model);
}
and in your strongly typed view:
@model IncidentsViewModel
@using (Html.BeginForm())
{
@Html.DropDownListFor(
x => x.SelectedIncidentId,
Model.Incidents,
"--Select a Incident--"
)
<button type="submit">OK</button>
}