从ActionLink将参数传递给Action Method [英] Passing parameters to Action Method from ActionLink

查看:97
本文介绍了从ActionLink将参数传递给Action Method的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想将下拉值传递给ActionLink的动作方法,但是在调试第二个参数时,第一个参数是空的。

查看我的代码。



Hi I want to pass dropdown values to action method from ActionLink but while debugging second parameter coming properly but first one is null.
Have a look at my code.

@Html.DropDownListFor(x => x.SelectedField, new SelectList(Model.Filter, "Id", "Name", Model.SelectedField),new { @class = "select1", style = "width:120px;" } )

@Html.DropDownListFor(x => x.SelectedYear, new SelectList(Model.ReportYears, "ID", "Name", Model.SelectedYear), new { @class = "select1", style = "width:120px;" })





action link =>





action link =>

@Html.ActionLink("Export to PDF", "DownloadRevenuePdfFile", "EmailReport", new { month = Model.SelectedField, year = Model.SelectedYear }, new { @class = "black" })





控制器





controller

public void DownloadRevenuePdfFile(string month, string year)





谢谢



thanks

推荐答案

您的链接是在编译时在服务器上计算的。因此,您的页面需要在进行选择时回发,以更新任何链接。因此,我将取消操作链接,而是使用您调用的方法,根据当前值计算链接并执行重定向。
Your link is calculated at compile time on the server. As such, your page needs to post back when a selection is made, to update any link. So I'd do away with the action link and instead have a method you call, which calculates the links and does a redirect, based on the current values.


这篇关于从ActionLink将参数传递给Action Method的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆