0

I have code that builds Urls in ASP.NET MVC3 using a RouteValueDictionary and UrlHelper. The problem that I am running into is that MVC calls ToString() on the types in the dictionary. For a particular type I am using, this is not the value that I want to be in the Uri. I cannot change the ToString implementation.

I understand how to create a ModelBinder to handle the deserialization from the Uri, but not the serialization part. How and what do I register in order to control how a type is converted to the Uri parameter?

Thanks, Erick

4

1 に答える 1

0

For a particular type I am using, this is not the value that I want to be in the Uri

Then don't use this type. Pass the value that you want directly as string in the dictionary:

rvd["key"] = "the value you want";

instead of:

rvd["key"] = new SomeType { Foo = "foo", Bar = "bar" };

The conversion between your type and its string representation should be handled elsewhere.

于 2012-07-20T05:53:08.777 に答える