views:

4784

answers:

4

I am currently building an application using ASP.NET MVC. The data entry pages are fairly easy to code, I just make the Model for the page of the type of my business object:

namespace MyNameSpace.Web.Views.ProjectEdit
{
    public partial class MyView : ViewPage<Project>
    {
    }
}

Where I am struggling is figuring out the best way to implement a dashboard like interface, with stand-alone parts, using ASP.NET MVC, where the Model for each part would be different? I'm assuming that each part would be an MVC user control.

Also, how could I make it so each part is testable?

A: 

Hi there,

I'm not familiar to MVC yet (I tries once in the beginning of the betas, but I thought it was "scary" omparing to webforms) so I'm shooting blanks here, but you might download the Storefont MVC and learn from it, or see the movies under http://www.asp.net/learn/mvc-videos/

I think that will help you accomplish what you need and have a better understanding on the MVC framework

balexandre
I will check these out ... I've watched some of the MVC videos, and while informative ... they usually stick to the kool-aid, instead of providing some meat.
mattruma
http://tekpub.com/production/aspmvc <-- Here's some meat for you, no affiliation. :)
Adam Nofsinger
+3  A: 

I think that user controls is probably the way to go. I'm not sure what the concern is about testability. You should be able to test that your controller is providing the right view data -- since you'll have several models each of these will probably be stored in a separate view data item, rather than aggregating them in a single model. Aggregating in a single model is also possible, although probably more brittle. Each control would just need to check for a particular view data item, rather than being specific to a particular model. You could approximate the model variable on each view page by doing:

<% MyUserControlModel model = ViewData["MyUserControlModel"]
         as MyUserControlModel; %>

<div id="myUserControl_dashboard" class="dashboard">
   Name: <%= model.Name %><br />
   Count: <%$ model.Count %>
</div>

If you need to test your view, then you're probably already using Selenium or some other web testing framework. I don't think that these would care how the page was constructed and you should be able to construct your tests pretty much like you always do.

tvanfosson
So let's say I have a HomeController ... and on the Index view I want to display X other user controls ... how would I do this?
mattruma
Create your DashboardView that renders each of the UserControls in the view placed as you want them. Have your Index action collect the models needed for each of the user controls and store each model in an appropriately named ViewData item. Each control need only render its data.
tvanfosson
(cont.) The Index action returns a ViewResult for the DashboardView with appropriate data for each of the user controls.
tvanfosson
+3  A: 

Check out the notion is sub-controllers in MVC-Contrib http://www.codeplex.com/MVCContrib. Basically you run a full request to a partial then display that partial where you want in your existing code.

Alternatively you can check out this post: http://blog.codeville.net/2008/10/14/partial-requests-in-aspnet-mvc/

Kyle West
A: 

Hi,

You can try Kalitte .Net Dashboard Toolkit. It lets you to create partial rendering iGoogle like dashboards in your Asp.Net application.

Visit http://www.dynamicdashboards.net for more info.