我知道这很简单,但对 Mvc 来说是新的。我想用 GetDescription 方法中的数据填充一个下拉框,以便下拉框显示描述,并在选择时将代码作为值传递。
我该如何编写html片段?
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public static List<Populate> GetDescription()
{
List<Populate> myInfor = new List<Populate>()
{
new Populate{Id=1,Description="Lagos", Code="lag"},
new Populate{Id=2,Description="Ibadan", Code="lba"},
new Populate{Id=3,Description="Akure", Code="Aku"},
new Populate{Id=4,Description="Ejigbo", Code="Eji"},
new Populate{Id=5,Description="Oshogbo", Code="Osh"}
};
return myInfor;
}
}
public class Populate
{
public int Id { get; set; }
public string Description { get; set; }
public string Code { get; set; }
}
Here is the html
*********************
@model PopulateDropDownList.Models.Populate
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.DropDownList(Model.id, Model.Description, "--Select One--")
</p>