Pregunta

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).

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top