我不知道我在这里做什么,但是任何和所有参数都以null
的形式传递给我的控制器,即使它们在呈现的HTML中已经明确定义。
查看
@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 :(得分: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 :(得分:1)
正在使用错误的重载,请尝试这样做:
@Html.ActionLink("Export to Spreadsheet", "Export", "ZipCodeTerritory"
,
new {
searchZip = Model.searchZip,
searchActiveOnly = Model.searchActiveOnly,
searchTerritory = Model.searchTerritory,
searchState = Model.searchState
}
, null)