tags:

views:

38

answers:

2

I'm trying to paginate the results of a "advanced search", I have a complex model that represents the search options;

int ZipCode
int MinAge
int MaxAge
Availability
    bool Monday
    bool Tuesday
    ...
    bool Friday
Requirements
    bool FirstAid
    bool DriversLicense

I'm using;

<%: Html.ActionLink("Next »", "Save", "Notification", Model.options)%>

Which correctly sends all the data at the first level, but anything that is a sub-object (Availability or requirements) isn't expanded in the URL, all I get is the class name and so I lose most of the search options when I click the link to change to a different page.

Any thoughts?

A: 

Somewhere down the line your Options object gets used as an argument to the RouteValueDictionary constructor:

http://msdn.microsoft.com/en-us/library/cc680272(v=VS.100).aspx

The code in that constructor does not recursively go down into the properties of your nested object. It only will reflect over the first level of your properties.

jfar
Yes, I'm aware that this is the case... I was looking for a solution.
Xenph Yan
@Xenph Yan "Any Thoughts?" led me to believe you didn't understand what was happening.
jfar
A: 

I ended up creating a overridden ToString() method, which converted the complex model to a query string. Then created a Flat model which mapped the query string and a convert method to pop me back out the original complex object.

I won't lie... It's a lot of a hack.

But it all works, and rather reliably.

Xenph Yan