Reputation: 2696
I have a ViewModel that is a very simple filter object like this:
public class FilterViewModel
{
public String FilterTerm { get; set; }
public String FilterProperty { get; set; }
}
what I was hoping to do was to do a route link from another page into this one and pass my FilterViewModel into the route url creation into the RouteValues like this:
Url.RouteUrl("myRoute", new { filter = new FilterViewModel() { FilterProperty = "Product", FilterTerm = _detail.FilterTerm }})"
Lo, what renders on the other side is
http://theurl?filter=Fully.Qualified.Namespace.FilterViewModel
I don't know what I expected, perhaps something that's serialized into the query string like this:
http://theurl?filter=FilterProperty|Product,FilterTerm|ProductA
Is there anyway to do what I'm trying to do out of the box? (or not out of the box)
Upvotes: 0
Views: 709
Reputation: 1038720
Try like this:
Url.RouteUrl(
"myRoute",
new {
FilterProperty = "Product",
FilterTerm = _detail.FilterTerm
}
)
No idea how your routing configuration looks like but this might produce something among the lines of http://theurl?FilterProperty=Product&FilterTerm=ProductA
. For anything more exotic like the urls you have shown in your question you will have to write custom helpers. It's nothing standard.
Upvotes: 1