简体   繁体   中英

Html.ActionLink() not working for passing a C# object

I'm trying to pass an object through an ActionLink to a method in an MVC controller.

The razor syntax:

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

What's actually being displayed in markup:

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

The controller method is being called just fine, hence no reason to post here. What needs to be done so that the actual values are passed into the actionLink instead of DTO.SearchObject ? According to HTML.ActionLink method it looks like I have the right syntax (using MVC 4).

You should be able to pass the DTO, assuming it's just that, as the parameter into ActionLink :

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

Any public fields will be added as a query parameter key/value pair.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM