【问题标题】:How to pass table's current rows fields to a PartalView如何将表的当前行字段传递给 PartalView
【发布时间】:2017-04-14 13:51:23
【问题描述】:

在我的MVC 视图中,我正在打开一个模式对话框,它将PartialView 呈现为RenderAction。当用户单击特定行的Add 按钮时,视图将打开,如下所示。

从主视图中,我想传递当前行的(选择行)ProjectNo、DrawingNo 和 RevisionNo。另外,最好我想将其传递到各自的 ViewBag's 字段中。我怎样才能做到这一点?

这是我调用对话框的源代码。

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
    <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="myModalLabel">Enter Fabrication Information</h4>
        </div>
        <div class="modal-body">
            <div>
                @{Html.RenderAction("Create", "Fabrication", new BPs.Entities.FABRICATION { });}
            </div>
        </div>
    </div>
</div>

更新:为每一行添加 html

@foreach(var info in @Model)
{
    <tr>
        <td>info.ProjectNo</td>
        <td>info.DrawingNo</td>
        <td>info.RevisionNo</td>
        <button >Add</button>
    </tr>
}

【问题讨论】:

  • 这可能会对您有所帮助:stackoverflow.com/questions/37844621/…
  • 您需要提供更多信息。每行的 html 是否包含 ProjectNoDrawingNo 等的数据(例如 data-* 属性)。显示典型行的 html 格式。
  • @StephenMuecke 请查看更新后的问题(我添加了表格的 html 外观示例)
  • 假设您处理按钮的.click() 事件,那么var row = $(this).closest (tr); 将获得当前行,row.find (td).eq (0).text(); 将获得第一个单元格的文本。
  • 我现在得到了那个部分,但是我如何将它发送到我正在使用 RenderAction 加载的视图?

标签: asp.net asp.net-mvc bootstrap-modal


【解决方案1】:

绑定添加到jquery事件并将值发送到事件函数('',''),然后使用加载函数打开部分视图

function Add(parameters)
{
    $("<div></div>")
       .addClass("dialog")                        
       .appendTo(".modal-body")
       .dialog({
           title: 'xx',
           close: function () { $(this).remove() },
           closeText: "Close",
           modal: true
       })
       .load("url?"yourparameters);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-01
    • 1970-01-01
    • 2012-09-26
    • 1970-01-01
    • 1970-01-01
    • 2013-08-17
    • 1970-01-01
    • 2016-08-27
    相关资源
    最近更新 更多