Search code examples
asp.net-mvct4mvc

asp.net mvc 3: reverse of modelbinder while serializing to url


In our application we have an object which is called a search descriptor. We have a custom modelbinder for it to make it all work. It reads certain know properties like q oorsort and page from the URL (or post data).

Now somewhere else in the application, we need a URL to the searchpage. We use the searchdescriptor class to model what we want to search for.

I needed a way to convert all the things in searchdescriptor to a routevaluedictionary and then merge that with the action name and controller name.

No a big deal, I just added it to the class. However, modelbinders let me extend mvc before my controller kicks in, I want something similar for serialization to URL.

We also use T4mvc, but passing a complex object to an action method just serializes it to the tostring.

Does this mechanism already exist? Or do we have to code this ourselves?


Solution

  • As of now the mechanism does not exist. We ended up only needing this for a couple of models, which we could do with just custom toQueryString code and t4mvc's 0-parameter action methods.