0

我有一个 ViewModel,它是一个非常简单的过滤器对象,如下所示:

public class FilterViewModel
{
    public String FilterTerm { get; set; }
    public String FilterProperty { get; set; }
}

我希望做的是做一个从另一个页面到这个页面的路由链接,并将我的 FilterViewModel 传递到路由 url 创建到 RouteValues 中,如下所示:

Url.RouteUrl("myRoute", new { filter = new FilterViewModel() { FilterProperty = "Product", FilterTerm = _detail.FilterTerm }})"

瞧,另一边的渲染是

http://theurl?filter=Fully.Qualified.Namespace.FilterViewModel

我不知道我的预期,也许是像这样序列化到查询字符串中的东西:

http://theurl?filter=FilterProperty|Product,FilterTerm|ProductA

无论如何我要做的就是开箱即用?(或不开箱即用)

4

1 回答 1

1

试试这样:

Url.RouteUrl(
    "myRoute", 
    new { 
        FilterProperty = "Product", 
        FilterTerm = _detail.FilterTerm 
    }
)

不知道您的路由配置如何,但这可能会在http://theurl?FilterProperty=Product&FilterTerm=ProductA. 对于您在问题中显示的网址等更具异国情调的内容,您将不得不编写自定义助手。这没什么标准。

于 2011-10-05T21:47:45.447 回答