代码之家  ›  专栏  ›  技术社区  ›  ryan

使用MVC返回部分页面

  •  0
  • ryan  · 技术社区  · 17 年前

    我是MVC的新手,希望我能以正确的方式实现这一点。任何意见或建议都会很好。

    问题是,当您单击较小的图像时,动态图像将成为整个页面。我意识到这是因为href指向的地方,但我需要一些指针,以正确的方式来实现这一点。

     <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>
    

    如果有人需要,这是ImageController。ImageActionResult获取内存流并返回图像

    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
    

    谢谢

    2 回复  |  直到 17 年前
        1
  •  1
  •   Mehrdad Afshari    17 年前

    您需要操纵 象元 使用客户端javascript,类似于:

    <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>
    
        2
  •  0
  •   James Skidmore    17 年前

    $('a.dynamicImage').colorbox({width: 75%, height: 75%});
    
    推荐文章