我按照这篇文章来做,可是最后在添加product时为什么没有category的下拉列表,还是以填写分类ID,模板中也没有生成DropDownlist的代码。这是为何?
VS2010 SP1 中文旗舰版+ SQL 2008 R2要如何实现分类的下拉列表功能?求解。

解决方案 »

  1.   

    View
    <select id="category" name="category">
    @foreach (var item in Model.category)

        <option@(item.Key == Model.categoryid ? new HtmlString(" selected=\"selected\"") : new HtmlString("")) value="@item.Key">@item.Value</option>
    }
    </select>
    Model
    public class ProductModel
    {
        public int categoryid { get; set; }
        public Dictionary<int, string> category { get; set; }
      

  2.   

    最后,还是看了MusicStore这个官方的项目里代码,已经解决了。