Jquery 在razor中将迭代数据从按钮传递到模式
我有一个razor视图页面,我在其中循环浏览我的列表,并将其逐行呈现在表中。在每一行,都有一个按钮,用于通过邮件发送存储在特定行中的信息,但该按钮本身并不触发邮件发送操作。它打开一个模式,并要求用户继续或不继续该过程。之后,模式中的按钮将触发邮件发送过程的javascript方法。这是我的循环Jquery 在razor中将迭代数据从按钮传递到模式,jquery,asp.net-mvc,twitter-bootstrap,razor,bootstrap-modal,Jquery,Asp.net Mvc,Twitter Bootstrap,Razor,Bootstrap Modal,我有一个razor视图页面,我在其中循环浏览我的列表,并将其逐行呈现在表中。在每一行,都有一个按钮,用于通过邮件发送存储在特定行中的信息,但该按钮本身并不触发邮件发送操作。它打开一个模式,并要求用户继续或不继续该过程。之后,模式中的按钮将触发邮件发送过程的javascript方法。这是我的循环 @foreach (var file in Model.ExcelLogListPaged) { <tr>
@foreach (var file in Model.ExcelLogListPaged)
{
<tr>
<td class="">@file.ID</td>
<td>@file.UploadedDate</td>
<td><button class="btn btn-info btn-lg" type="button" data-toggle ="modal" data-target="#warningModal" id="sendMailButton_@file.ID">Send Mail</button></td>
</tr>
}
@foreach(Model.ExcelLogListPaged中的var文件)
{
@file.ID
@file.uploadeDate
寄信
}
这是我的模态
div id="warningModal" class="modal fade" role="dialog" style="z-index:9999;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Are you sure?</h4>
</div>
<div class="modal-body">
<p>Are you sure to send the mail manually?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-success" data-dismiss="modal">Send</button>
</div>
</div>
</div>
</div>
div id=“warningModal”class=“modal fade”role=“dialog”style=“z-index:9999;”>
&时代;
你确定吗?
您确定要手动发送邮件吗
接近
发送
正如我提到的,我有一个javascript方法
SendMail()
,负责发送邮件。我想通过模态按钮触发它,这就是为什么我需要通过onclick
属性分配它。但是,此方法需要一个参数,此参数应通过模态的调用者按钮传递。更具体地说,我想将数据@file.ID
从循环传递到我的model,然后使用它分配给model的submit按钮的onclick
属性,如SendMail(@file.ID)
。我该怎么做?提前感谢。将fileid属性添加到循环中的按钮,任何css类都会显示“file”
@foreach (var file in Model.ExcelLogListPaged)
{
<tr>
<td class="">@file.ID</td>
<td>@file.UploadedDate</td>
<td><button fileid="@file.ID" class="btn btn-info btn-lg" type="button" data-toggle
="modal" class="file" data-target="#warningModal" id="sendMailButton_@file.ID">Send Mail</button></td>
</tr>
}
div id="warningModal" class="modal fade" role="dialog" style="z-index:9999;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Are you sure?</h4>
</div>
<div class="modal-body">
<p>Are you sure to send the mail manually?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-
dismiss="modal">Close</button>
<button type="button" class="btn btn-success" data-
dismiss="modal">Send</button>
<input type="hidden" id="hdnselectedfield" />
</div>
</div>
</div>
</div>
<script>
$(".file").on("click",function(){
$("#hdnselectedfield").val($(this).val()))
})
</script>
SendMail($("#hdnselectedfield").val())