ASP.NET MVC Strongly Typed Widgets
Posted
by Ben
on Stack Overflow
See other posts from Stack Overflow
or by Ben
Published on 2010-05-14T15:05:42Z
Indexed on
2010/05/14
15:24 UTC
Read the original article
Hit count: 414
asp.net-mvc
I have developed a plugin system that makes it easy to plug in new logic to an application. Now I need to provide the ability to easily add UI widgets.
There are already some good responses on how to create a portal system (like iGoogle) with ASP.NET MVC, and I'm fine about the overall concept.
My question is really about how we make strongly typed widgets.
Essentially when we set up a widget we define the controller and action names that are used to render that widget. We can use one controller action for widgets that are not strongly typed (since we just return PartialView(widgetControlName) without a model)
For widgets that are strongly typed (for example to an IList) we would need to add a new controller action (since I believe it is not possible to use Generics with ActionResult e.g. ActionResult).
The important thing is that the widget developers should not change the main application controllers. So my two thoughts are this:
- Create new controllers in a separate class library
Create one partial WidgetController in the main web project and then extend this in other projects (is this even possible?)- not possible as per @mfeingold
As far as the development of the widgets (user controls) go, we can just use post build events from our extension projects to copy these into the Views/Widgets directory.
Is this a good approach. I am interested to here how others have handled this scenario.
Thanks Ben
P.S - in case it helps, an example of how we can render widgets - without using Javascript
<%foreach (var widget in Model) {%>
<%if (widget.IsStronglyTyped) {
Html.RenderAction(widget.Action, widget.Controller);
} else {
Html.RenderPartial(widget.ControlName);
}
%>
<%} %>
© Stack Overflow or respective owner