0

我正在創建一個名爲「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找不到。

+0

爲什麼要補充型號1命名空間?在此之上,您使用Autonomous_Framework_Rsoff.Brand –

+0

參考模型。爲什麼您在控制器中的View方法中傳遞「brandRepository」?相反,你應該通過「brandList」。還像@Steve說的那樣,爲什麼要在模型名稱空間中添加Model1? –

+0

你應該在這裏使用DI。正如@SteveGreene所說,命名空間與控制器中引用的名稱空間不同。我相信如果改變它與控制器中的一樣,它應該可以工作。 –

回答

0

通過看你的代碼中,有兩個地方需要糾正:

IEnumerable<Autonomous_Framework_Rsoff.Brand> brandList = brandRepository.GetAll(); 

return View(brandList); 

@model IEnumerable<Autonomous_Framework_Rsoff.Brand> 
+0

謝謝這麼多它修復:) –

+0

@HamnaRashid很高興它有幫助!你能否將它標記爲答案?謝謝。 –

+0

我是新的沒有足夠的聲譽將其標記爲答案。一旦我得到它,我會回來這樣做:) –