views:

27

answers:

1

Hello. I've got a search form that I want to use short query string parameters for (e.g. ?q=value&s=whatever&c=blah) and I'd like to use MVC model binding to get those parameters into my controller action.

I can create a type that mirrors these short names, but I'd rather have a type that has more sensible names (e.g. q = Query, s = SortOrder, c = Cheese). Is there a nice simple way I can do this, such as attributes on my model?

I know I can write a new model binder for this, but that feels like overkill - I'm not doing anything complicated, just using different names) - and it feels wrong to have to suddenly have to be quite so explicit.

Since the model binding infrastructure uses TypeDescriptors, I guess I could specify a custom type descriptor on my model that returns properties with different names, presumably from attributes on the model itself - at least this would be usable.

Anyway, I was hoping someone had already done this?

+1  A: 

Writing your own model binder is overkill but it's the way to do it. The binding in MVC uses reflection so you need a 1:1 match.

The other way would be to write a small class that has your fields in it that look like you want them to look and then bind the view to that.

Then in your controller you can grab those values the normal binding way and then transfer those (nice) looking fields to the other model you have.

griegs
I've done that. Custom binder.
Arnis L.