我想询问是否可以将输入字段中的值传递给@ Html.Action的第三个参数,以便访问控制器方法。这是我的代码:
在我看来: 这是将id传递给输入的脚本。
<script type="text/javascript">
$(document).on("click", ".desktop_id", function () {
var deskId = $(this).data('id');
$(".modal-body #idd").val(deskId);
});
</script>
以下是显示动作部分视图的模式
<a data-toggle="modal" data-id="@item.desktop_info_id" title="Add this item" class="desktop_id" href="#myModal1"><i title="Actions" class="fa fa-th"></i></a>
<!-- Modal -->
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title" id="myModalLabel1">Actions</h4>
</div>
<div class="modal-body">
<input type="text" name="idd" id="idd" value=""/>
@Html.Action("Transaction", "Desktop", new {id=---need to be field---})
</div>
<div class="modal-footer">
<button type="button"class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
@ Html.Action(“事务”,“桌面”,新的{id = ---需要填充---})第三参数是否可以从中获取相同的id值?输入字段,以便我可以将其传递给控制器?感谢。
答案 0 :(得分:0)
尝试直接从jQuery函数重定向到您的操作:
<script type="text/javascript">
$(document).on("click", ".desktop_id", function () {
var deskId = $(this).data('id');
var url = '@Html.Raw(Url.Action("Transaction", "Desktop", new { id = "_id" }))';
url = url.replace("_id", deskId);
window.location(url);
});
</script>
答案 1 :(得分:0)
我想我明白你需要什么。你的模态取决于id,所以你可以像
一样直接使用它<a data-toggle="modal" data-id="@item.desktop_info_id" title="Add this item" class="desktop_id" href="#@item.desktop_info_id"><i title="Actions" class="fa fa-th"></i></a>
注意:此处href="#@item.desktop_info_id"
使用了动态ID
同时为模态设置相同的ID:id="@item.desktop_info_id"
<div class="modal fade" id="@item.desktop_info_id" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title" id="myModalLabel1">Actions</h4>
</div>
<div class="modal-body">
<input type="text" name="idd" id="idd" value=""/>
@Html.Action("Transaction", "Desktop", new {id=item.desktop_info_id})
</div>
<div class="modal-footer">
<button type="button"class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<强>更新强>
在这里摆弄样本,似乎都有效:dotnetfiddle