让我试着回顾一下我从你的问题理解为:你有包含您想列id
和name
绑定到一个select
数据库表countries
元素在视图中。如果这是正确的,你可以尝试做这样的事情:
public ActionResult Index()
{
IEnumerable<Country> countries = FetchCountriesFromDB();
var model = new SelectList(countries, "Id", "Name", null);
return View(model);
}
而在你的强类型的视图:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<System.Web.Mvc.SelectList>" %>
...
<%= Html.DropDownList("country", Model) %>
,最后你可以有你发布到一个动作:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(string country)
{
// country will contain the selected country id
...
}
其实,我尝试使用MVC的Contrib输入建设者,我知道了MVC的内置的东西:) – Omu 2009-11-12 13:05:18
我设法做一个输入我自己的建筑师,所以现在没问题 – Omu 2009-11-12 13:29:09