I pretty new to ASP.NET MVC so my apologies if the question sounds lame. I was watching the ASP.NET Storefront video series and Rob uses ComponentControllers to display data in the master page. How do I implement this in the latest release of MVC? I've read
about SubContollers in MVC Contrib but I dont know how and if I should use it - I'm totally confused. Bump!
Any sort of help would be greatly appreciated.
Thanks
ComponentController asp.net mvc 1.0
Be nice to geeks, you might end up working for one
Please hit "MARK AS ANSWER" if I made you smile today ;)
ComponentController was removed long ago and replaced with RenderAction, which is in MVC Futures right now (and will be part of mainline MVC 2 when we ship the Beta).
Marked as answer by ricka6 on Nov 09, 2009 07:16 PM
ComponentController was removed long ago and replaced with RenderAction, which is in MVC Futures right now (and will be part of mainline MVC 2 when we ship the Beta).
Thanks Brad. If that is the case then I how can I display data in my master page? I dont want to put any data access logic inside my master page. Any suggestions?
Be nice to geeks, you might end up working for one
Please hit "MARK AS ANSWER" if I made you smile today ;)
You can use RenderAction from inside of a MasterPage. Just make an action and associated partial view for whatever it is you want to render in the Master Page.
Marked as answer by ricka6 on Nov 09, 2009 07:17 PM
Brad, I was curious what you thought about RenderAction from a pattern perspective...doesn't that break the MVC paradigm? To speak in hyperbole, you could have a ViewPage that only has a RenderAction in the ContentPlaceHolder, wouldn't that defeat the purpose?
Brad, I was curious what you thought about RenderAction from a pattern perspective...doesn't that break the MVC paradigm?
Speaking as me, and not as a member of the MVC team, yes I believe that RenderAction breaks the MVC paradigm. It's not a feature that I intend to use, personally, as I prefer compound view models (or use of ViewData) as the proper way in MVC, even if it
feels less convenient than RenderAction.
You can pass new models to RenderPartial. That's what I would suggest for most cases (MasterPages are the obvious exception, since they always have to use the same model as the top-level view).
Something tells me that it wasn't the MVC team that 'slipped it in' rather were given strong requests from the user base that wanted it even though said user base didn't understand what they were asking for.
Dsypher
Member
350 Points
98 Posts
ComponentController in ASP.NET MVC 1.0 - Has it been removed?
Nov 08, 2009 04:07 PM|LINK
Hi,
I pretty new to ASP.NET MVC so my apologies if the question sounds lame. I was watching the ASP.NET Storefront video series and Rob uses ComponentControllers to display data in the master page. How do I implement this in the latest release of MVC? I've read about SubContollers in MVC Contrib but I dont know how and if I should use it - I'm totally confused. Bump!
Any sort of help would be greatly appreciated.
Thanks
ComponentController asp.net mvc 1.0
Please hit "MARK AS ANSWER" if I made you smile today ;)
bradwils
Contributor
5779 Points
691 Posts
Microsoft
Re: ComponentController in ASP.NET MVC 1.0 - Has it been removed?
Nov 08, 2009 04:46 PM|LINK
ComponentController was removed long ago and replaced with RenderAction, which is in MVC Futures right now (and will be part of mainline MVC 2 when we ship the Beta).
Dsypher
Member
350 Points
98 Posts
Re: ComponentController in ASP.NET MVC 1.0 - Has it been removed?
Nov 09, 2009 04:11 AM|LINK
Thanks Brad. If that is the case then I how can I display data in my master page? I dont want to put any data access logic inside my master page. Any suggestions?
Please hit "MARK AS ANSWER" if I made you smile today ;)
bradwils
Contributor
5779 Points
691 Posts
Microsoft
Re: ComponentController in ASP.NET MVC 1.0 - Has it been removed?
Nov 09, 2009 06:47 PM|LINK
You can use RenderAction from inside of a MasterPage. Just make an action and associated partial view for whatever it is you want to render in the Master Page.
nicequy
Contributor
2652 Points
496 Posts
Re: ComponentController in ASP.NET MVC 1.0 - Has it been removed?
Nov 10, 2009 01:06 AM|LINK
Brad, I was curious what you thought about RenderAction from a pattern perspective...doesn't that break the MVC paradigm? To speak in hyperbole, you could have a ViewPage that only has a RenderAction in the ContentPlaceHolder, wouldn't that defeat the purpose?
<asp:Content ContentPlaceHolderID="MainContent" runat="server"> <% Html.RenderAction<ControllerName>(c => c.GetPageContent()); %> </asp:Content>Would using RenderAction make using RenderPartial not as attractive if the PartialView has its own model?
I have been using a Filter that places MasterPage content in ViewData. Would you recommend RenderAction over ViewData?
Thanks in Advance,
Jason Conway
MCP, MCTS, Certified SCRUM Master
asp.net blog
bradwils
Contributor
5779 Points
691 Posts
Microsoft
Re: ComponentController in ASP.NET MVC 1.0 - Has it been removed?
Nov 10, 2009 01:24 AM|LINK
Speaking as me, and not as a member of the MVC team, yes I believe that RenderAction breaks the MVC paradigm. It's not a feature that I intend to use, personally, as I prefer compound view models (or use of ViewData) as the proper way in MVC, even if it feels less convenient than RenderAction.
You can pass new models to RenderPartial. That's what I would suggest for most cases (MasterPages are the obvious exception, since they always have to use the same model as the top-level view).
Dsypher
Member
350 Points
98 Posts
Re: ComponentController in ASP.NET MVC 1.0 - Has it been removed?
Nov 10, 2009 04:17 AM|LINK
I totally agree with Brad. I guess the MVC team slipped in the RenderAction helper for the exceptional cases like MasterPages
Please hit "MARK AS ANSWER" if I made you smile today ;)
nicequy
Contributor
2652 Points
496 Posts
Re: ComponentController in ASP.NET MVC 1.0 - Has it been removed?
Nov 10, 2009 04:28 AM|LINK
Something tells me that it wasn't the MVC team that 'slipped it in' rather were given strong requests from the user base that wanted it even though said user base didn't understand what they were asking for.
MCP, MCTS, Certified SCRUM Master
asp.net blog