Hi,
I'm not sure what I am doing wrong here, not even sure if I am on the right track. I have a view model and I create a drop down list from it. Here is my view model:
public class ApplicationViewModel
{
public Application Application { get; private set; }
public SelectList AccountTypes { get; private set; }
public ApplicationViewModel(Application application, IEnumerable<AccountType> accountTypes)
{
Application = application;
AccountTypes = new SelectList(accountTypes, "AccountTypeID", "AccountTypeName", application.AccountTypeID);
}
}
Here is my Create (get) action:
public ActionResult Create()
{
var viewModel = new ApplicationViewModel(new Application(), db.AccountTypes);
return View(viewModel);
}
And my view code:
<%: Html.DropDownListFor(???, Model.AccountTypes, "-- Select --") %>
<%: Html.ValidationMessageFor(???) %>
In the code above, I'm not exactly sure what must come in ??? The initial value is "-- Select --". If the user clicks on the submit button and the dropdown's value is still "-- Select --" then it must display a message.
I am also using EF4. Please can someone advise as to what to do. Code samples would be appreciated.
Thanks.