请帮我找到我所缺少的东西。 url.content没有在foreach循环中返回每个项目的视频,而是为每个元素显示相同的视频。我想访问我桌子的videofilepath列中的每个视频,并将其显示在模态上(仍在进行中)。
@foreach (var item in Model)
{
<div class="col-md-4 portfolio-item">
<img class="img-responsive img-thumbnail"
src='@item.PosterFilePath'alt="thumbnail" />
<strong> @Html.DisplayNameFor(model => model.Title)</strong>
@Html.DisplayFor(modelItem => item.Title)
<br>
<strong>@Html.DisplayNameFor(model => model.ReleaseDate)</strong>
@Html.DisplayFor(modelItem => item.ReleaseDate)
<br>
<strong>@Html.DisplayNameFor(model => model.Genre)</strong>
@Html.DisplayFor(modelItem => item.Genre)
<br>
<strong> @Html.DisplayNameFor(model => model.Price)</strong>
@Html.DisplayFor(modelItem => item.Price)
<br>
<strong>@Html.DisplayNameFor(model => model.Rating)</strong>
@Html.DisplayFor(modelItem => item.Rating)
<br>
<div class="">
<button class="btn btn-primary" type="button" data-toggle="modal" data-target="#ajax">Watch now</button>
<button class="btn btn-success" type="button"><span class="glyphicon-download"></span>Download</button>
</div>
<br>
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</div>
<div class="modal fade" id="ajax">
<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">×</span>
</button>
<h3>@Html.DisplayNameFor(model => model.Title)</h3>
</div>
<div class="modal-body">
<video id="video" poster="~/Images/algo.jpg"
controls="controls"
loop="loop">
<source src="@Url.Content(item.VideoFilePath)" type="video/mp4">
</video>
</div>
<div class="modal-footer">
<button type="button" id="btnClose" class="btn btn-primary" data-dismiss="modal"><span class="glyphicon-folder-close"></span>Close</button>
<button type="button" class="btn btn-success">Download</button>
</div>
</div>
</div>
</div>
}
答案 0 :(得分:0)
您的模态 div 需要具有唯一ID。如果你有视频的Id作为模型的一部分,你可以添加或附加它:
<div class="modal fade" id="ajax@(Model.VideoId)"
和调用它的按钮相同:
<button class="btn btn-primary" type="button" data-toggle="modal" data-target="#ajax@(Model.VideoId)">Watch now</button>