使用ActionLink打开Modal并在MVC中传递参数 [英] Use ActionLink to open Modal and pass parameter in MVC
问题描述
我试图通过在ActionLink上单击并传递如下所示的参数来在同一页面上打开引导程序模式:
I am trying to open my bootstrap modal on the same page by clicking on the ActionLink and passing a parameter as below:
@foreach (Items item in Model)
{
@Html.ActionLink("Download", "#", new { data-id = '@item.Name' } )
}
//Modal
<div id="dModal" class="modal hide fade" aria-hidden="true">
<div class="modal-body">
@using (Html.BeginForm("getCSV", "Download", new { filename = data-id }, FormMethod.Post, null))
{
<button id="btnCSV" type="submit">Download CSV</button>
}
//other options for excel, word etc
</div>
</div>
在ActionLink中,我将actionName参数保留为#,这是因为模态位于同一页面上,并且当用户在模态中选择选项时将决定操作.不直接调用下载操作方法的原因是因为用户可以选择以各种格式下载excel,csv等.
In the ActionLink I have kept actionName parameter to #, this is because the modal is on the same page and the action will be decided when the user selects the options in the modal. The reason for not calling the download action method directly is because the user has options to download in various formats excel, csv etc.
推荐答案
这是我如何使用html.actionlink显示引导模态形式
This is how I show a bootstrap modal form using an html.actionlink
@Html.ActionLink("ModalPopUp", "#", new { id = parameter }, new { @data_toggle = "modal", @data_target = "#YourModalId"})
这篇关于使用ActionLink打开Modal并在MVC中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!