views:

599

answers:

1

I hope my terminology is right. Edit if not.

From my Linq2Sql classes I have a Color class. One of my controller's actions accepts an instance of this Color class.

I want to create a link to this action so I use

<%=Html.ActionLink<ColorController>(c=>c.Details(ViewData.Model.ActiveColor), "test")%>

Where ViewData.Model.ActiveColor is off course the aforementioned instance of Color.
This renders as follows:

/Color/Details?color=- Not exactly what I had in mind off course..

What am I doing wrong? Should I start creating custom ModelBinders?

EDIT
I have found where the "-" came from. Apparantly the ActionLink is calling upon ToString. This is rather weird since I see tostring more of way to display something then to identify something (isn't that what GetHash is for?). Even after implementing the Iserailizable interface on my object, it's still using the ToString method. Can I define somewhere how to serialize my class rather then using the ToString()? I'm feeling like I'm completely on the wrong track.

A: 

Actionlink is indeed calling upon ToString(). I ran into the same problem using dates. In my urls I wanted dates to be dd-mm-yyyy instead of the default DateTime.ToString().

First option is to override your Color's ToString() method. If that isn't possible (as with DateTime) there are other ways, but they're a bit "hacky"...

Casper