您的位置:首页 > 编程语言 > ASP

ASP.NET MVC HtmlHelper =>Html.DropDownList

2009-10-25 23:21 417 查看

用法一:

Controller Action:

为什么为什么

public ActionResult DropDownList()
{
NorthwindEntities ne = new NorthwindEntities();
var p = ne.Categories;

List<SelectListItem> items = new List<SelectListItem>();
foreach(var n in p)
{
var item = new SelectListItem { Value  = n.CategoryID.ToString(), Text  = n.CategoryName };
items.Add(item);
}
ViewData["l"] = items;
return View();

View:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h2>CategoryDropDownList</h2>
<%=Html.DropDownList("l") %>
</asp:Content>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: