Reputation: 10709
Not sure what I'm doing here but any and all parameters are coming through to my controller as null
even though they are clearly defined in the rendered HTML.
View
@Html.ActionLink("Export to Spreadsheet", "Export", "ZipCodeTerritory"
, new {
@searchZip = Model.searchZip,
@searchActiveOnly = Model.searchActiveOnly,
@searchTerritory = Model.searchTerritory,
@searchState = Model.searchState
})
Controller
public ActionResult Export(string searchZip, bool? searchActiveOnly, string searchTerritory, string searchState)
{
Rendered HTML
<a href="/ZipCodeTerritory/Export?Length=16" searchactiveonly="True" searchstate="CA" searchterritory="" searchzip="">Export to Spreadsheet</a>
Upvotes: 0
Views: 74
Reputation: 33326
It is using the wrong overload, try this instead:
@Html.ActionLink("Export to Spreadsheet", "Export", "ZipCodeTerritory"
,
new {
searchZip = Model.searchZip,
searchActiveOnly = Model.searchActiveOnly,
searchTerritory = Model.searchTerritory,
searchState = Model.searchState
}
, null)
Upvotes: 1
Reputation: 289
You're using the wrong overload for Html.ActionLink. It's thinking that your route values are actually html attributes. Additionally, you'll need to remove the "@"s in each of your variable names. Try changing this:
@Html.ActionLink("Export to Spreadsheet", "Export", "ZipCodeTerritory"
, new {
@searchZip = Model.searchZip,
@searchActiveOnly = Model.searchActiveOnly,
@searchTerritory = Model.searchTerritory,
@searchState = Model.searchState
})
To this:
@Html.ActionLink("Export to Spreadsheet", "Export", "ZipCodeTerritory"
, new {
searchZip = Model.searchZip,
searchActiveOnly = Model.searchActiveOnly,
searchTerritory = Model.searchTerritory,
searchState = Model.searchState
}, null)
Upvotes: 2