1
votes

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:

  1. Create new controllers in a separate class library
  2. 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);
      } 
    %>

<%} %>
3

3 Answers

1
votes

For me it seems that MvcContrib's portable areas fits for developing independent widgets perfectly.

Here is an example - OpenId authentication widget.

Next week You can even watch c4mvc presentation about it.

1
votes

The answer to your second question is NO. all source code for partial classes should be in the same project.

0
votes

Is it possible with the templating engine to create a template for your widget type, then just call <%: Html.EditorForModel(untypedWidgetModel) %> - in theory, your template for that type would then take over and render appropriate HTML.

Or have I misunderstood how templating can work?