Thanks to the feedback of the 2 responders I have decided that creating a strongly typed model was the best approach. Since my model was generated from the db I needed to create a partial class so that I would not lose changes if db model refreshed. I created the partial class which is a type of my model class
namespace TouchScreenEvents
{
[MetadataType(typeof(TouchScreenEventMetadata))]
public partial class TouchScreenEvent
{
public string selectedHour { get; set; }
public List<SelectListItem> hours = new List<SelectListItem>()
{
new SelectListItem() {Text="9a", Value="09"},
new SelectListItem() {Text="10a", Value="10"},
new SelectListItem() {Text="11a", Value="11"},
new SelectListItem() {Text="12p", Value="12"},
new SelectListItem() {Text="1p", Value="13"},
new SelectListItem() {Text="2p", Value="14"},
new SelectListItem() {Text="3p", Value="15"},
new SelectListItem() {Text="4p", Value="16"},
new SelectListItem() {Text="5p", Value="17"},
new SelectListItem() {Text="6p", Value="18"},
new SelectListItem() {Text="7p", Value="19"},
new SelectListItem() {Text="8p", Value="20"}
};
public string selectedMinute { get; set; }
public List<SelectListItem> minutes = new List<SelectListItem>()
{
new SelectListItem() {Text="00", Value="00"},
new SelectListItem() {Text="30", Value="30"}
};
}
}
To set the selected index in the controller I have this code (unnecessary parts removed)
//get edit touchscreen event
TouchScreenEvent touchScreenEvent = await db.TouchScreenEvents.FindAsync(id);
var d = touchScreenEvent.date;
touchScreenEvent.selectedMinute= d.ToString("mm");
touchScreenEvent.selectedHour = d.ToString("HH");
And the view code, with previously selected value set. This will also work without the selected index being set - in the create view for instance
@Html.DropDownListFor(model => model.selectedHour, Model.hours, htmlAttributes: new { @class = "form-control" })
@Html.DropDownListFor(model => model.selectedMinute, Model.minutes, htmlAttributes: new { @class = "form-control" })
When posted back to the controller I can access the values like this
touchScreenEvent.selectedHour, touchScreenEvent.selectedMinute