views:

461

answers:

2

Hi,

I'm trying to retreive data from a massive form using Asp.net MVC. Its top object L1 contains properties which are Collections of other types L2. However the Type L2 contains some properties which collections of type L3, and so on. There are probably 5 levels of nested collections.

I've seen the approach of binding to Lists in Asp.Net MVC, where the element name has an array substring included in the names of all its propertie html elements, e.g. [0] in the first set, [1] in the second set etc.

However when we've got nested objects, its going to be quite tricky / nightmare to go town[0].council[0].street[0].Name and use that convention to name the html elements.

Has anyone come across this situation / can see an elegant way to resolve it?

Thanks

Mickey

A: 

You may want to consider using LINQ to abstract the nitty gritty for you and allow you to perform joins and whatnot on the lists.

James
+1  A: 

The default model binder that ships with ASP.NET MVC is what dictates the form element naming convention you are referring to. If there is another convention that you would like to use to name the form elements, go for it. Then you just have to write a custom model binder that can populate your nested objects based on your convention.

There are lots of tutorials out there for creating model binders, here are some:

http://www.singingeels.com/Articles/Model_Binders_in_ASPNET_MVC.aspx

http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/03/17/a-better-model-binder.aspx

AJ