2013-12-17 229 views
0

不知道我在這裏做什麼,但任何和所有參數都通過我的控制器作爲null即使它們在呈現的HTML中明確定義。路由參數通過null

查看

@Html.ActionLink("Export to Spreadsheet", "Export", "ZipCodeTerritory" 
    , new { 
     @searchZip = Model.searchZip, 
     @searchActiveOnly = Model.searchActiveOnly, 
     @searchTerritory = Model.searchTerritory, 
     @searchState = Model.searchState 
    }) 

控制器

public ActionResult Export(string searchZip, bool? searchActiveOnly, string searchTerritory, string searchState) 
    { 

渲染HTML

<a href="/ZipCodeTerritory/Export?Length=16" searchactiveonly="True" searchstate="CA" searchterritory="" searchzip="">Export to Spreadsheet</a> 
+0

在參數字典中的@是不是必需的,可能是什麼是扔掉這個。您呈現的HTML對於URL來說相當糟糕,這意味着它是無法正常運行的ActionLink助手。看起來ActionLink正在將您的路線參數改爲「」標籤屬性。嘗試刪除ActionLink – Tommy

+0

的'new {}'部分中的@將其刪除,但仍然沒有運氣。也注意到關於呈現的鏈接,但是刪除'@'並沒有改變任何東西。 – NealR

回答

2

您使用的是錯誤的Html.ActionLink過載。它認爲你的路由值實際上是html屬性。此外,您需要刪除每個變量名稱中的「@」。嘗試改變這一點:

@Html.ActionLink("Export to Spreadsheet", "Export", "ZipCodeTerritory" 
, new { 
    @searchZip = Model.searchZip, 
    @searchActiveOnly = Model.searchActiveOnly, 
    @searchTerritory = Model.searchTerritory, 
    @searchState = Model.searchState 
}) 

要這樣:

@Html.ActionLink("Export to Spreadsheet", "Export", "ZipCodeTerritory" 
, new { 
    searchZip = Model.searchZip, 
    searchActiveOnly = Model.searchActiveOnly, 
    searchTerritory = Model.searchTerritory, 
    searchState = Model.searchState 
}, null) 
+1

此外,可以將控制器移動到RouteValue字典中,然後不需要使用Html.ActionLink(LinkTExt,Action,RouteValues)過載 – Tommy

1

它使用了錯誤的過載,試試這個:

@Html.ActionLink("Export to Spreadsheet", "Export", "ZipCodeTerritory" 
    , 
    new { 
     searchZip = Model.searchZip, 
     searchActiveOnly = Model.searchActiveOnly, 
     searchTerritory = Model.searchTerritory, 
     searchState = Model.searchState 
    } 
    , null)