Asp.net mvc 使用Html.ActionLink重定向视图
我有以下问题: 我调用控制器的方法,它接收一个参数。 代码如下:Asp.net mvc 使用Html.ActionLink重定向视图,asp.net-mvc,asp.net-mvc-3,controller,html.actionlink,Asp.net Mvc,Asp.net Mvc 3,Controller,Html.actionlink,我有以下问题: 我调用控制器的方法,它接收一个参数。 代码如下: @Html.ActionLink("Preview", "ReportExecution", "Report", new { reportName = ViewBag.docLiquidation }, null) [HttpPost] public FileResult ReportExecution(string reportName) { . . return new File(); }
@Html.ActionLink("Preview", "ReportExecution", "Report", new { reportName = ViewBag.docLiquidation }, null)
[HttpPost]
public FileResult ReportExecution(string reportName)
{
.
.
return new File();
}
这将为我生成以下地址:
http://localhost:65500/Report/ReportExecution/docRetentionDeclaration
docRetentionDeclaration已标识为参数,但未标识
该方法的代码如下:
@Html.ActionLink("Preview", "ReportExecution", "Report", new { reportName = ViewBag.docLiquidation }, null)
[HttpPost]
public FileResult ReportExecution(string reportName)
{
.
.
return new File();
}
我感谢您能给我的帮助。假设您有以下路线:
routes.MapRoute(
"Default",
"{controller}/{action}/{reportName}",
new { controller = "Home", action = "Index", reportName = UrlParameter.Optional }
);
控制器操作将期望参数名为reportName:
public ActionResult ReportExecution(string reportName)
{
...
}
请注意控制器操作的参数名称必须与路由定义中的路由令牌相匹配。当然,参数名称与路由相对应。[HttpPost]公共文件结果报告执行字符串报告名称[HttpPost]????您希望如何调用一个只接受带有锚点的POST动词的方法?