【发布时间】:2015-03-11 11:57:33
【问题描述】:
我有这个将在控制器中调用的函数:
public EditViewModel PostEditViewModel(EditViewModel model)
{
using (var db = new NorthwindEntities())
{
var prod = db.Products.Where(x => x.Id == model.Id).Single();
{
prod.Id = model.Id;
...
//I need something like this:
//prod.CategoryID = model.CategoryList.CatId
//but obviously intellisense tells me that after the dot of CategoryList, only methods of that list can be called.
db.SaveChanges();
}
这是我的 ViewModel:
public int Id{ get; set; }
...
public IEnumerable<Categories> CategoryList { get; set; }
public class Categories {
public int ProdId { get; set; }
public int? CatId { get; set; }
public string CatName { get; set; }
}
如何通过我的 EditViewModel 调用 CategoryList,以便我可以通过 HTML.DropdownList 编辑特定产品的 Category?
【问题讨论】:
-
您可以在视图中发布您的 DropDownList 的剃刀/标记吗?
-
@Html.DropDownList("CategoriesDropdown", Model.CategoryName)
标签: c# asp.net-mvc entity-framework model-view-controller