我有 1 个项目名称 MVC1
我有以下 2 节课:
public class category
{
public int ID {get;set;}
public string Name {get;set;}
}
public class detail
{
public int Id {get;set;}
public string Name {get;set;}
public int CategoryID{get;set;}
}
和 2 个接口
public inteface ICategory
{
IList<category> ListCategory();
}
public interface IDetail
{
IList<Detail> ListDetail();
}
和 1 模型 RCateory 从接口 ICategory 继承
public IList<Category> FindAllCategory()
{
List<Category> Listcategory_ = new List<Category>();
foreach (var category in Listcategory)
{
Listcategory_.Add(category);
}
return Listcategory_;
}
和 1 模型名称 RDetail 从接口 IDetail 继承
public IList<Detail> FindAllDetail()
{
List<Detail> Listdetail_ = new List<Detail>();
foreach (var detail in Listdetail_)
{
Listdetail_.Add(detail);
}
return Listdetail_;
}
和 1 个控制器
DetailController
private RDetail rDetail = new RDetail();
private RCategory rCategory = new RCategory();
public ActionResult ListDetail()
{
var detail = rdDetail;
return View("CreateDetail");
}
和 1 个视图类型 (cshtml) CreateDetail 容器
@model MVC1.Detail
我如何将类别放入@Html.DropDownListFor