【问题标题】:RenderPartial and popup modal MVC C#RenderPartial 和弹出模式 MVC C#
【发布时间】:2017-11-14 18:37:21
【问题描述】:

我在索引视图中有一些代码

@foreach (var item in Model){
<tr><td>......</td>
    <td><button class="success" data-toggle="modal" data-target="#detailsModal" >details</button>
        <div class="modal fade" id="detailsModal" tabindex="-1" role="dialog" aria-labelledby="detailsModalLabel" aria-hidden="true">
             @{Html.RenderPartial("_Details", item);}
        </div></td></tr>}

但是在不同行上单击我的按钮后,弹出窗口总是显示数据库的第一项。我怎样才能改变它?

控制器

        public ActionResult Details(int? id)
    {
        DBase dbase = new DBase();
        dbase = db.DBase.Find(id);
        return PartialView("_Details", dbase);
    }

【问题讨论】:

    标签: c# asp.net-mvc popup modal-dialog renderpartial


    【解决方案1】:

    由于您的 foreach 循环,您在 HTML 中声明了具有相同 IDmultiple 模态。

    所以它只使用它找到的第一个模态元素。要解决此问题,请为您的每个模式提供一个唯一的 ID。

    因此,您可以通过向其添加索引来更改 data-target="#detailsModal"id="detailsModal",使其类似于 id="detailsModal-1"

    【讨论】:

      猜你喜欢
      • 2012-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多