Let me try to recap what I understood from your question: you have a database table countries
that contains columns id
and name
that you would like to bind to a select
element in a view. If this is correct you could try doing something like this:
public ActionResult Index()
{
IEnumerable<Country> countries = FetchCountriesFromDB();
var model = new SelectList(countries, "Id", "Name", null);
return View(model);
}
And in your strongly typed view:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<System.Web.Mvc.SelectList>" %>
...
<%= Html.DropDownList("country", Model) %>
and finally you could have an action that you post to:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(string country)
{
// country will contain the selected country id
...
}