Html.BuildUrlFromExpression with reference type parameters for action
I hope my terminology is correct. Edit if not.
From my Linq2Sql classes, I have a Color class. One of my controller actions takes an instance of this Color class.
I want to link to this activity, so I use
<%=Html.ActionLink<ColorController>(c=>c.Details(ViewData.Model.ActiveColor), "test")%>
In cases where ViewData.Model.ActiveColor is detached from the above Color instance.
It looks like this:
/ color / detail color =? - Not exactly what I meant outside the course.
What am I doing wrong? Should I create custom ModelBinders?
EDIT
I found where "-" came from. Obviously ActionLink is calling ToString. This is kind of weird as I see tostring more ways to display something then to identify something (not what GetHash is for?). Even after implementing the Iserailizable interface on my object, it still uses the ToString method. Can I figure out somewhere how to serialize my class and then use ToString ()? It seems to me that I am completely wrong.
source to share
Actionlink actually calls ToString (). I faced the same problem using dates. In my urls, I wanted the dates to be dd-mm-yyyy and not the default DateTime.ToString ().
The first option is to override the Color ToString () method. If this is not possible (as in DateTime) there are other ways, but they are a bit "hacky" ...
source to share