Thanks Abombss, Rob.
Yes, this is a general problem...so I am wondering if ASP.NET will have some neat solution.
As my understanding partials in RoR is just a piece of presentation code (should belongs to View), so actually I had same problem when I played on RoR before. (though it's possible to put some M&C code inside partial, it's ugly) As you mentioned we can archive the same goal with RenderUserControl() in ASP.NET.
I think the key problem is not in the view part, it's inside M & C. A dashboard web page could pull all kind of data in the database, if we mix all those inside the M&C, it will be a mess. Yes, we can put those modulized logic into "services", we can even encapsulate them into different classes / assemblies / ..., however we need a place to put them together...then we may get a messed up "action". Image a real complex application, many actions may contain similar codes though those are just simple calls to some encapsulated services.
e.g.
public class BigWebController : Controller {
[ControllerAction]
public void Index()
{
LatestNewsService latestNews = new LatestNewsService();
StockQuotoService stock = new StockQutoService();
...
// we at least need to create and call those services somewhere, right?
RenderView(...);
}
public void MyCustomizedDashboard()
{
...
// we may have similar code here, right?
RenderView("...")
}
}
For the views, we can use user control, or simple "include" some aspx files which render partial content (is the include a good idea? I am very new to asp.net, but I did quite a lot such include in Java web develop) Since we have prepared all required data in M, C, we will get whatever we want in the V.
What if we need to add some "component" to a web page? Oh, besides change the view aspx files, we have to change the controller code, even those component are remain exactly same in another page!
This is not a neat enough idea sounds to me, because we not treat it as "component", we separated something which could done perfectly in a full M-V-C cycle into "service" and "partial" .
If we need to consider the cache, the logic could be much complex: we
may have a bunch of condition code somewhere to get "Model" from cache,
but how about the view? if Model can be get from cache, why we render
view again? would it better to directly pull the result from cache?
-----
What I did before is: (I didn't use asp.net before, so write some Java related stuff, but I believe it similar)
(1) Keep MVC stuff simple and only do one task in each MVC cycle. (It's not conflict to implement stuff as service)
(2) Use another container page to "include" each part of the "components", this could be a simple jsp page or another "MVC" cycle.
I think my solution have those advatange:
* it's like real "component", they are self-contained.
* change the finally page is simple, just change the external contain page, you get different result. (the project I worked before, the web design changes from time to time, maybe we just have poor design and decision but that's real in many teams I believe... )
* it's easy to switch from "service side include" to "ajax include", just change the container page, all component remain unchanged! In one of my project, we even switch between the 2, if user agent support javascript, we use ajax, if not we use server side include, and it's very SEO friendly.
* The huge benefit I think is CACHE. We can have many level cache to archive best performance, in the container page level, we can use cached result if nothing changed from any inside component, for "component" they have cache for themselves, and the cache mechanism is same for the whole page and the "component", it's simple and very efficient.
I think the solution I have is like a "reversed" master page: the "container" page dispatch to each "component" and composite into a final web page. ASP.NET's master page is a great idea, however I am wonder if how to archive the above dash board alike application easily and keep the design neat and clean.
---
Of course, maybe I am wrong or maybe there are much better solution for this, that's what I am looking for and why I asked the question here.