繁体   English   中英

@ html.Action通过输入类型传递值

[英]@html.Action pass value from an input type

我想问一下如何将值从输入字段传递到@ 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">&times;</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(“ Transaction”,“ Desktop”,新的{id = ---需要填写---})第三参数如何可能从输入字段中访问id值,因此我可以将其传递给控制器​​? 谢谢。

尝试直接从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>

我想我了解您的需求。 您的模态取决于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">&times;</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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM