I build my web site using asp.net mvc3, layout is 2 columns, main content with sidebar.
I create a section for sidebar. this sidebar will show top 10 articles. what I did right now is to query the top 10 articles on every controller.
is there a way to do it in one place and using it on all controllers?
You can do this using
Html.RenderAction([methodname], [controllername]). So in your _Layout.cshtml, you might end up with something like:Then in your
ArticleController:Marking the action with the attribute
ChildActionOnlymeans it can only be invoked by a call toHtml.Action()orHtml.RenderAction().