views:

153

answers:

2

I am pretty new to MVC and hope that I am approaching this the correct way. Any input or advice would be great.

I would like to have a thumbnail view of an image load normally and when a user clicks on the image, the dynamic picture loads using the colorbox jquery plugin.

The problem is when you click on the smaller image, the dynamic image becomes the entire page. I realize its because of where the href is pointing to, but I need some pointers as to a correct way to accomplish this.

 <div id="gallery">

    <% For Each item In Model%>

    <ul>
        <li>
            <a href="<%=Url.Action("CreateWM", "Image", New With {.id = item.ImageID })%>" title="Please work" rel="Test">
                <img src="<%=Url.Action("Create", "Image", New With {.id = item.ImageID })%>" width="300" height="300" alt="Woot" />
            </a>
        </li>
    </ul>

    <% Next%>

</div>

In case someone needs it, this is the ImageController. The ImageActionResult is taking the memory stream and returning the image

Public Class ImageController
   Inherits System.Web.Mvc.Controller

    Public Function CreateWM(ByVal id As String) As ImageActionResult

        Using db As New DataClasses1DataContext
            Dim ms As New MemoryStream(db.MyImages.Single(Function(x) x.ImageID = id).ImageData.ToArray())
            Return New ImageActionResult(ms, "hey.jpg", True)
        End Using

    End Function

    Public Function Create(ByVal id As String) As ImageActionResult

        Using db As New DataClasses1DataContext
            Dim ms As New MemoryStream(db.MyImages.Single(Function(x) x.ImageID = id).ImageData.ToArray())
            Return New ImageActionResult(ms, "hey.jpg", False)
        End Using

    End Function

End Class

Thanks

A: 

You need to manipulate the URL of the image element using client side javascript, something like:

<a href="#" onclick="$('#myImg')[0].src='<%=Url.Action("CreateWM", "Image", New With {.id = item.ImageID })%>'" title="Please work" rel="Test">
     <img id="myImg" src="<%=Url.Action("Create", "Image", New With {.id = item.ImageID })%>" width="300" height="300" alt="Woot" />
</a>
Mehrdad Afshari
Mehrdad, thanks for the fast reply. The CreateWM is not being called when I click on the image now using what you provided me.
What I wrote is more like a pseudocode. You might want to do $("#myImg").src instead...
Mehrdad Afshari
I guess this new one should work... Not tested though.
Mehrdad Afshari
still not finding myImg, I changed it to try and do a simple height change and that is not working either. hmmm..
Mehrdad Afshari
well it works when I put an example in site.master but I can not get it working where I need it. Crazy
A: 

With the ColorBox plugin that you are using, you can specify the width/height of the dynamic image:

$('a.dynamicImage').colorbox({width: 75%, height: 75%});
James Skidmore