Asp.net mvc 3 带有ViewModel的RouteValue

Asp.net mvc 3 带有ViewModel的RouteValue,asp.net-mvc-3,model-view-controller,routedata,Asp.net Mvc 3,Model View Controller,Routedata,我有一个ViewModel,它是一个非常简单的过滤器对象,如下所示: public class FilterViewModel { public String FilterTerm { get; set; } public String FilterProperty { get; set; } } Url.RouteUrl("myRoute", new { filter = new FilterViewModel() { FilterProperty = "Product",

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

public class FilterViewModel
{
    public String FilterTerm { get; set; }
    public String FilterProperty { get; set; }
}
Url.RouteUrl("myRoute", new { filter = new FilterViewModel() { FilterProperty = "Product", FilterTerm = _detail.FilterTerm }})"
http://theurl?filter=FilterProperty|Product,FilterTerm|ProductA
Url.RouteUrl(
    "myRoute", 
    new { 
        FilterProperty = "Product", 
        FilterTerm = _detail.FilterTerm 
    }
)
我希望做的是从另一个页面到这个页面的路由链接,并将我的FilterViewModel传递到路由url创建到RouteValue,如下所示:

public class FilterViewModel
{
    public String FilterTerm { get; set; }
    public String FilterProperty { get; set; }
}
Url.RouteUrl("myRoute", new { filter = new FilterViewModel() { FilterProperty = "Product", FilterTerm = _detail.FilterTerm }})"
http://theurl?filter=FilterProperty|Product,FilterTerm|ProductA
Url.RouteUrl(
    "myRoute", 
    new { 
        FilterProperty = "Product", 
        FilterTerm = _detail.FilterTerm 
    }
)
瞧,在另一面呈现的是

http://theurl?filter=Fully.Qualified.Namespace.FilterViewModel
我不知道我期望的是什么,可能是序列化到查询字符串中的内容,如下所示:

public class FilterViewModel
{
    public String FilterTerm { get; set; }
    public String FilterProperty { get; set; }
}
Url.RouteUrl("myRoute", new { filter = new FilterViewModel() { FilterProperty = "Product", FilterTerm = _detail.FilterTerm }})"
http://theurl?filter=FilterProperty|Product,FilterTerm|ProductA
Url.RouteUrl(
    "myRoute", 
    new { 
        FilterProperty = "Product", 
        FilterTerm = _detail.FilterTerm 
    }
)
我想做的事有没有现成的方法?(或不是开箱即用)

尝试以下方法:

public class FilterViewModel
{
    public String FilterTerm { get; set; }
    public String FilterProperty { get; set; }
}
Url.RouteUrl("myRoute", new { filter = new FilterViewModel() { FilterProperty = "Product", FilterTerm = _detail.FilterTerm }})"
http://theurl?filter=FilterProperty|Product,FilterTerm|ProductA
Url.RouteUrl(
    "myRoute", 
    new { 
        FilterProperty = "Product", 
        FilterTerm = _detail.FilterTerm 
    }
)

不知道路由配置看起来如何,但这可能会在
http://theurl?FilterProperty=Product&FilterTerm=ProductA
。对于任何更奇特的东西,比如你在问题中显示的URL,你必须编写自定义帮助程序。没什么标准。

好吧,太棒了。。。我把事情复杂化了。。。这是解决我问题的正确方法。。。我想我必须在控制器的方法参数中模拟这种结构。。。但我没有这样做,我将我的方法参数保持为:MyAction(FilterViewModelFilter)并且它绑定正确。。。谢谢你的帮助,我有时会挂断模型装订的电话。