Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay Image from DB in Modal Bootstrap Window
    primarykey
    data
    text
    <p>I'm using ASP.net MVC5 with Bootstrap 3 I have the following <strong>View</strong></p> <pre><code>@model WilhanWebsite.Models.PhotoViewModel @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } &lt;h2&gt;Gallery&lt;/h2&gt; &lt;p&gt; @Html.ActionLink("Upload Photo", "Create") &lt;br/&gt; @for (var i = 0; i &lt; Model.DownloadedImages.Count; i++) { &lt;a data-toggle="modal" data-target="#img-thumbnail@i" class="img_modal" href="data:image/jpg;base64,@(Convert.ToBase64String(Model.DownloadedImages[i].ImageData))"&gt; &lt;img id="img-thumbnail@i" class="img-thumbnail" src="data:image/jpg;base64,@(Convert.ToBase64String(Model.DownloadedImages[i].ImageData))" alt="@Model.DownloadedImages[i].Description" /&gt; &lt;/a&gt; } &lt;div id="modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt; &lt;div class="modal-header"&gt; &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;×&lt;/button&gt; &lt;h3 id="myModalLabel"&gt;Title to go here&lt;/h3&gt; &lt;/div&gt; &lt;div class="modal-body"&gt; &lt;img id="modal_img_target"&gt; &lt;/div&gt; &lt;div class="modal-footer"&gt; &lt;button class="btn" data-dismiss="modal" aria-hidden="true"&gt;Close&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/p&gt; </code></pre> <p>When I click an image from the gallery I would like it to display in a modal window.</p> <p>My problem is, when I click the link, the modal window displays without the image. All the examples I've seen use images from the file system whereas my site uses images from a db via a byte array. I guess the fix may be to change the line of javascript that is assigning the source attribute on the modal image but I've tried various things here without a result. The problem can be seen at the following address: <a href="http://wilhan.azurewebsites.net/Photo" rel="nofollow">Problem page</a></p> <p>** EDIT ** Updated view to use for loop to identify images as suggested. Problem changed, now rather than displaying a blank modal page, the image is displayed on a blank page.</p> <p>** EDIT Working View **</p> <pre><code> @model WilhanWebsite.Models.PhotoViewModel @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } &lt;h2&gt;Gallery&lt;/h2&gt; &lt;p&gt; @Html.ActionLink("Upload Photo", "Create") &lt;br/&gt; @for (var i = 0; i &lt; Model.DownloadedImages.Count; i++) { &lt;a data-toggle="modal" data-target="#img-thumbnail@i" class="img_modal" href="data:image/jpg;base64,@(Convert.ToBase64String(Model.DownloadedImages[i].ImageData))"&gt; &lt;img id="img-thumbnail@i" class="img-thumbnail" src="data:image/jpg;base64,@(Convert.ToBase64String(Model.DownloadedImages[i].ImageData))" alt="@Model.DownloadedImages[i].Description" /&gt; &lt;/a&gt; } &lt;div id="modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt; &lt;div class="modal-header"&gt; &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;×&lt;/button&gt; &lt;h3 id="myModalLabel"&gt;Title to go here&lt;/h3&gt; &lt;/div&gt; &lt;div class="modal-body"&gt; &lt;img id="modal_img_target"&gt; &lt;/div&gt; &lt;div class="modal-footer"&gt; &lt;button class="btn" data-dismiss="modal" aria-hidden="true"&gt;Close&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/p&gt; &lt;script type="text/javascript"&gt; $('.img_modal').on('click', function (e) { e.preventDefault(); $("#modal_img_target").attr("src", this); $("#modal").removeClass("hide"); $('#modal').modal('show'); }); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload