1
我的網站有不斷增加的數量的不同控制器,根據各地具體的實體,實現接口/ Repository模式來填充各種視圖。大多數這些視圖都綁定到單個頁面。詳細信息,索引等MVC:動態內容的設計策略未綁定到單頁
這個實體的數據也顯示,主要是在總結/壓緊形式,在其他頁面,如定製的主頁,杆和側杆(使用佈局和欄目)。
我不確定哪種方法使用。我有2記:
1)導入相關庫到頁面模板/側邊欄模板:
public HomeController(IMessagesRepository messagesRepository, ICruiseCalendarRepository cruiseCalendarRepository, INewsRepository newsRepository, and so on and so on...)
//
{
this.repoMessages = messagesRepository;
this.repoCruiseCalendar = cruiseCalendarRepository;
this repoNews = newsRepository;
and so on
and on
....
....
}
......從這些或建立網頁。
2)使用Html.RenderAction的訪問通過控制器的動態數據:
<div class="newsBox">
@{ Html.RenderAction("CustomisedHeadlines", "News");}
</div>
<div class="messageBox">
@{ Html.RenderAction("LatestMessages", "Messages");}
</div>
<div class="calendarBox">
@{ Html.RenderAction("WeekItinerary", "CruiseCalendar");}
</div>
,以最好的設計實踐任何建議,將受到歡迎。
問候,蓋伊