0
私は基本的に、ブートストラップモーダルを使ってデータベースにある単一の製品の詳細を表示しようとしています。MVC ASP.Netのデータベースからのデータを含むブートストラップモーダルを表示
以下のコードでは、どのボタンを選択しても、いずれかの製品の詳細だけをクリックすることができます。
私が間違っていると思います。あなたの助けが大変ありがとうございます。以下のコードスニペット:
@foreach (var product in Model.Products)
{
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">
@product.ProductName
</button>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog" data-backdrop="true">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content" style="margin-bottom: 20px">
<div class="modal-header" style="padding:35px 50px;">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4>@product.ProductName</h4>
</div>
<div class="modal-body" style="padding:40px 50px;">
<div class="img-rounded col-md-5">
<img class="img-circle" src="@Url.Action("RenderImage", "Products", new { id = product.ProductID})" width="150" height="150"/>
</div>
<div class="col-md-7">
<p float="right">@product.ProductDescription</p>
</div>
</div>
<div style="margin-top:100px" class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
}
変数を設定して、あなたにこのID「i」が変数になります=「myModal」+私のようなモーダルポップアップのためのデータ・ターゲットとid値をインクリメントするか、または製品のクリックでajax呼び出しを行い、モーダル内の詳細を設定します –
基本的に、すべての単一モーダルでID属性を複製しています。すべてのボタンは同じモーダルターゲットを持つため、1つのモーダルしか表示されません。 –
ありがとうございました!私は基本的にデータターゲットを "#myModal - @(product.productID)"に編集しました。それは完全に動作しているようです!ありがとうございました – Mavric