我正在創建一個名爲「SaleModule」的MVC4網站。我在名爲「Autonomous_Framwork_Rsoff」的解決方案中添加了另一個項目,其中有一個存儲庫和模型(實體框架)。我在MVC項目中添加了「Autonomous_Framwork_Rsoff」的引用。這是控制器代碼:無法在視圖中訪問模型。 Used Repository and EntityFramwork
public ActionResult outletdisplay()
{
var dataContext = new AutonomousEntities1();
var brandRepository = new Repository<Autonomous_Framework_Rsoff.Brand>(dataContext);
var outletRepository = new Repository<Autonomous_Framework_Rsoff.Outlet>(dataContext);
IEnumerable<Autonomous_Framework_Rsoff.Brand> brandList = brandRepository.GetAll();
return View(brandRepository);
}
GetAll是一個函數庫,它將獲得所有品牌。 現在這是視圖的代碼。
@model IEnumerable<Autonomous_Framework_Rsoff.Model1.Brand>
但是第一行出現錯誤@ model IEnumerable紅線出現在Model1下。 Autonomous_Framework_Rsoff.Model1找不到。
爲什麼要補充型號1命名空間?在此之上,您使用Autonomous_Framework_Rsoff.Brand –
參考模型。爲什麼您在控制器中的View方法中傳遞「brandRepository」?相反,你應該通過「brandList」。還像@Steve說的那樣,爲什麼要在模型名稱空間中添加Model1? –
你應該在這裏使用DI。正如@SteveGreene所說,命名空間與控制器中引用的名稱空間不同。我相信如果改變它與控制器中的一樣,它應該可以工作。 –