ASP.NET MVC dropdownlist

后端 未结 4 1077
后悔当初
后悔当初 2021-02-06 09:35

Can someone point me to an article that shows the dropdownlist being populated from linq to sql (text and value being set).

Thanks Danny

4条回答
  •  被撕碎了的回忆
    2021-02-06 10:07

    Here's one great article by Rob Connery

    Controller Code

    NorthwindDataContext db = new NorthwindDataContext();
    var categories = from c in db.Categories select c;
    ViewData["CategoryID"] = new SelectList(categories, "CategoryID", "CategoryName");
    

    View Markup

    <%=Html.DropDownList("CategoryID")%>
    

提交回复
热议问题