gpt4 book ai didi

c# - Html.ActionLink() 不适用于传递 C# 对象

转载 作者:太空狗 更新时间:2023-10-29 21:17:51 25 4
gpt4 key购买 nike

我正在尝试通过 ActionLink 将对象传递给 MVC Controller 中的方法。

Razor 语法:

@Html.ActionLink("Export to Excel","ReturnExcelOfViewableResponses",new { SearchObject = Model.SearchObject})

标记中实际显示的内容:

<a href="/EducationAgency/ReturnExcelOfViewableResponses?SearchObject=DTO.SearchObject" tabindex="29">Export to Excel</a>

Controller 方法被调用得很好,因此没有理由在这里发布。需要做什么才能将实际值传递到 actionLink 而不是 DTO.SearchObject?根据HTML.ActionLink method看起来我的语法正确(使用 MVC 4)。

最佳答案

您应该能够将 DTO 传递给 ActionLink,假设它只是这样,作为参数传递给 ActionLink:

@Html.ActionLink("Export to Excel","ReturnExcelOfViewableResponses",Model.SearchObject)

任何公共(public)字段都将作为查询参数键/值对添加。

关于c# - Html.ActionLink() 不适用于传递 C# 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18412992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com