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

I am trying to pass an object via ActionLink to a method in the MVC controller.

Razor Syntax:

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

What is actually displayed in the markup:

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

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

+6
source share
1 answer

You should be able to pass DTO, considering this exactly as a parameter in ActionLink :

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

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

+9
source

Source: https://habr.com/ru/post/952397/


All Articles