viewModel.CategoryList = new SelectList(db.Categories, "ID", "Name", product.CategoryID);
@Html.DropDownListFor(vm => vm.CategoryID, Model.CategoryList, htmlAttributes: new {@class = "form-control" })
在"ID" == product.categoryID
答案 0 :(得分:0)
尝试
在控制器上
viewBag.Categories = new SelectList(db.Categories,“ ID”,“ Name”,product.CategoryID);
在视图上
@ Html.DropDownListFor(vm => vm.CategoryID,(selectlist)viewBag.Categories,htmlAttributes:new {@class =“ form-control”})