For me, I'm not using the prompt property... I actually didn't know about it so great to know. But I populate a strongly-typed view data with my list of items from my controller, and then pass it into my view. I, too, have to populate it with an extra item, in my case, i have a list of timezones, so my default item says "Select a timezone". I insert that item from my controller, so that my view doesn't have to worry about it. In fact, I like doing it as so because the controller now has control of what id to provide for this extra item, which causes it to not have to assume what id the view might use for this additional item. So it looks like this: (I've modified it slightly so it's easier to follow)
// In my controller code
public void Register()
{
Execute<RegisterViewData>(RegisterGet, RegisterPost); // Execute is a method in my base controller ... it determines which of the passed in methods to call based on the HttpMethod
// in this case, it will call RegisterGet
}
private void RegisterGet(RegisterViewData viewData)
{
using (var db = Database)
{
List<Timezone> timezones = new List<Timezone> { new Timezone{ ID = 0, DisplayName = "Select a Time Zone" };
timezones.AddRange((from tz in db.Timezones
where tz.Display
orderby tz.DisplayPriority descending, tz.ID ascending
select tz).ToArray());
viewData.Timezones = timezones.AsEnumerable();
}
RenderView("Register"); // Under the covers, the viewData that was passed into this method is the same view data that is passed to the view
}
// In my view
<%= Html.Select(ViewData.TimezoneIDElementId, ViewData.Timezones, "DisplayName", "ID", ViewData.TimezoneID) %> // ViewData is an instance of my strongly typed ViewData