I have a dropdown on my homepage that I need to bind to a data source when the page loads. I have a basic controller for the page:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
I'd like to do something like this on the view page:
<select id="ddlCities">
<% foreach (var item in ViewData.Model.Cities) { %>
<option value='<%= item.CityID %>'><%= item.CityName %></option>
<% } %>
</select>
So do I need to modify my Index() function to return a View Model? I'm coming from Web Forms and a little confused about how this works.