我在我的MVC控制器中有一个方法,当调用下载文档时。是否有可能将动态值添加到@ Html.ActionLink参数
我有一个bootstrap模态,其中href驻留指向此方法。
@Html.ActionLink("Download", "Download", new { applicantId = 1, templateId = 1 })
的applicantId和templateId对于分钟是硬编码,但这些值是通过jQuery的文本值传递给模态。
是否可以动态获取HTML标识并将其添加到@ Html.ActionLink?
模态:
<div id="template1">
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<h3 id="app" style="display:none"></h3>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">Letter Template Logo</h4>
</div>
<div class="modal-body">
<img style="background-size:cover;" src="~/Content/images/image.png" alt="" />
</div>
<div class="modal-footer">
ActionLink("Download", "Download", new { applicantId = 1, templateId = 1 })
</div>
</div>
</div>
</div>
</div>
其真不明白你问这里。 '@ Html.ActionLink()'是剃须刀代码,并且在发送到视图之前在服务器上解析,所以如果您想根据客户端中可用的数据更改生成的'href'属性,那么您需要javascript。而且你不能使用ajax来下载文件。您需要重定向到该方法。 –
@StephenMuecke发布后,我读了不能通过ajax做到这一点。我问,我可以将传递给模态的值绑定到html.actionlink参数吗? – Haris
您需要使用javascript/jquery来更改'href'属性。或者,取消默认操作并构建自己的url并使用'location.href'重定向并下载文件。 (当你没有显示控制器方法或者指出'applicantId'和'templateId'的值来自哪里时,很难给出答案) –