As usual, having trouble with SelectList in the MVC framework. The selected value is never set for some reason:
public class MyViewModel
{
public DateTime? SelectedServiceTime { get; set; }
public IEnumerable<DateTime> AvailableServiceTimes { get; set; }
public SelectList ServiceTimesList
{
get
{
SelectList selectList = new SelectList(AvailableServiceTimes, SelectedServiceTime.ToString());
return selectList;
}
}
}
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MyViewModel>" %>
<asp:Content ID="MainContent" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
<%using (Html.BeginForm()) { %>
<%:Html.DropDownListFor(x => x.SelectedServiceTime, Model.ServiceTimesList, new { size = 6 }) %><br />
<input type="submit" name="nextButton" value="Next" />
<%} %>
</asp:Content>