After reviewing Rob Conery's post, a few notes:
<% Html.RenderAction<PersonComponentController>(c=>c.List()); %>
routes.IgnoreRoute("PersonComponent/{action}");
My personal opinion is that this violates the separation of concerns so important to the MVC pattern. Having a method within your view calling back into a controller in order to render out a bit more view makes me feel a wee bit dirty ;). We’re developing prototypes for an alternative approach. In the meanwhile, I recognize that for a small sacrifice of pattern purity, this method is very useful, hence its inclusion in the MVC Futures assembly, but do understand that you use it at your own risk.
Yeah, and these components need route data and other stuff from the view. It will be interesting to see what they come up with so that I can just drag in my UberGrid and forget about all this coding. (kidding!)
For now, this works and it's testable.
3 Responses
Zuhaib | ASP.NET MVC Preview 4 Released
18|Jul|2008 1[...] First impressions on the new RenderAction method, again by Matt Hinze [...]
Ben Scheirman
18|Jul|2008 2Why separate components from regular controllers? It seems like what you need to do is call an action but render a specialized partial view… very similar to the ones we use when doing ajax calls.
Why not:
<% Html.RenderAction(c=>c.List(true /*partial */)); %>
then your action can look like this:
public ActionResult List(bool partial)
{
var sponsors = // load sponsors
if(partial)
return View("_sponsors", sponsors);
ViewData["sponsors"] = sponsors;
return View();
}
Matt
18|Jul|2008 3So in CodeCampServer it would be like this? (I do like the underscore naming convention for partials..)
public ActionResult List(string conferenceKey, bool partial, SponsorLevel? level)
{
Conference conference = _conferenceRepository.GetConferenceByKey(conferenceKey);
Sponsor[] sponsors = level.HasValue ? conference.GetSponsors(level.Value) : conference.GetSponsors();
ViewData.Add(sponsors);
if (partial) return View("_sponsors");
return View();
}
Leave a reply