我的MVC控制器中有一个方法,该方法在调用时会下载一个文档。
我有一个引导程序模式,href驻留在其中,它指向此方法。
@Html.ActionLink("Download", "Download", new { applicantId = 1, templateId = 1 })
分钟的applicantId和templateId被硬编码,但是这些值通过jquery作为文本值传递给Modal。
是否可以动态获取HTML ID并将其添加到@ 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>
javascript参考方案
我创建了.NetFiddle。它有效here
您可以使用Html.ActionLink()
方法更改.replace()
方法参数,并且可以实现如下所示。
// html
Parameter 1:<input id="param1" />
Parameter 2:<input id="param2" />
<div class="modal-footer">
@Html.ActionLink("Download", "Example", new { applicantId = 1, templateId = 1 })
</div>
<button id="yourbutton">Change Action Link</button>
// jquery
<script type="text/javascript">
$("#yourbutton").on("click",function(){
var param1 = $("#param1").val();
var param2 = $("#param2").val();
console.log(param1);
console.log(param2);
var link = '@Html.ActionLink("Download", "Example",
new { applicantId = "_applicantId_", templateId = "_templateId_"})';
if(param1 == "" || param2 == "")
{
alert("please fill all parameter inputs")
}
else
{
link = link.replace('_applicantId_', param1);
link = link.replace('_templateId_', param2);
$(".modal-footer").html(link)
alert("I have changed ActionLink. Please click the download link")
}
})
</script>
html onClick打开url存储在php变量中 - javascript以下是我的代码,正在获取Uncaught SyntaxError: Unexpected token },但是我的代码中没有看到任何}。 window.open期望用引号引起来的url,我尝试了单引号和双引号的不同组合,但不起作用并且也无法在echo中转义双引号。请帮助谢谢..<?php $a = "https://www.google.co…
Mongo汇总 - javascript我的收藏中有以下文件{ "_id": ObjectId("54490b8104f7142f22ecc97f"), "title": "Sample1", "slug": "samplenews", "cat": …
PHP stringID无法从回显中读入onclick - javascript我有一个音频播放器,可以在HTML中正常工作,但是当我从PHP回显调用时,似乎没有得到div ID的名称,因此它无法播放我的音频。这是我的代码:// Show audio if ($sObj->get('audio') != null) { $sAudio = $sObj->get('audio'); $a…
如果复选框切换复选框已选中,则在切换div中输入必填字段 - javascript我使用脚本用JavaScript切换了一些div。如果要选中复选框以显示toogle div,我想在toogle div中设置一些“必填”输入字段。有人能弄清楚吗?那是工作吗?function show(id) { if(document.getElementById) { var mydiv = document.getElementById(id); m…
在php中单击按钮添加表行并设置字段值 - javascript我有一个表单,必须在单击按钮时添加表行。这是我必须动态添加的表行:(addProdToGroup.php)<tr style="text-align: center;" id="products"> <td><?php $j ?></td> <td><s…