2011-10-05 45 views
0

我有一個視圖模型這是一個非常簡單的過濾器對象是這樣的:RouteValues有一個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 

反正有做我想做的開箱? (或不開箱)

回答

1

嘗試這樣的:

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

不知道你的路由配置的樣子,但這可能會產生的http://theurl?FilterProperty=Product&FilterTerm=ProductA在電線之間的東西。對於您在問題中顯示的url更爲異乎尋常的內容,您將不得不編寫自定義幫助程序。這沒什麼標準。

+0

好吧,太棒了......我太過複雜了......這是我的問題的正確實施......我想我必須在控制器的方法參數中模仿這個結構......但是我確實不,我保持我的方法參數爲:MyAction(FilterViewModel過濾器),並且它正確綁定...感謝您的幫助,我有時會掛上模型綁定。 – Rikon

相關問題