Redirect view with Html.ActionLink
-
18-06-2021 - |
Question
I have the following problem: I make the call to the method of a controller, it receives a parameter. The code is as follows:
@Html.ActionLink("Preview", "ReportExecution", "Report", new { reportName = ViewBag.docLiquidation }, null)
This generates me the following address:
http://localhost:65500/Report/ReportExecution/docRetentionDeclaration
docRetentionDeclaration identified as a parameter, but does not.
The code of the method is as follows:
[HttpPost]
public FileResult ReportExecution(string reportName)
{
.
.
return new File();
}
I appreciate the help you can give me.
La solution
Assuming you have the following route:
routes.MapRoute(
"Default",
"{controller}/{action}/{reportName}",
new { controller = "Home", action = "Index", reportName = UrlParameter.Optional }
);
the controller action will expect the parameter to be called reportName:
public ActionResult ReportExecution(string reportName)
{
...
}
Notice how the parameter name of the controller action must match the route token in your route definition.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow