如何在Bootstrap Modal Popup中加载局部视图并将参数传递给actionresult以在模态窗口加载时加载网格?

时间:2014-09-23 11:35:43

标签: jquery asp.net-mvc twitter-bootstrap

在Bootstrap Modal弹出窗口中加载局部视图存在问题。我可以将prodId作为参数传递给模态弹出窗口吗?

控制器操作:

[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Details(string INFO)
{
    return PartialView("DetailsPartialView");
}

型号:

<div class="modal" id="DetailsPopup" tabindex="-1" role="dialog" data-backdrop="static"
  data-keyboard="true" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      @Html.Partial("../Controller/DetailsPartialView")
    </div>
  </div>
</div>

按钮:

<button type="button" class="btn btn-default" id="btnDetails">Details</button>

$("#btnDetails").click(function () {
    $('#DetailsPopup').appendTo("body").modal('show');
});

1 个答案:

答案 0 :(得分:0)

您可以将数据传递到Html.Partial中:

<div class="modal" id="DetailsPopup" tabindex="-1" role="dialog" data-backdrop="static" data-keyboard="true" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            @Html.Partial("../Controller/DetailsPartialView", new { id = yourId })
        </div>
    </div>
</div>

然后您就像在常规视图中一样在局部视图中使用它。如果您对此更熟悉,也可以传递模型类。