2012-06-04 62 views
0

我正在使用ASP.NET MVC3和jQuery Cycle Plugin構建圖像庫項目。這是我的代碼有:獲取當前照片的ID當前照片jQuery圈幻燈片庫

$(document).ready(function() { 
    $('#s1').cycle({ 
     fx: 'curtainX', 
     speed: 2000, 
     next: '#raty', 
     timeout: 0, 
     after: Rate 
    }); 
}): 

我從頁面源代碼如下列表:

<div id="s1" class="slides">  
    <img src="/Photo/Thumbnail/14?size=large" title="walk 071" alt="14" /> 
    <img src="/Photo/Thumbnail/15?size=large" title="walk 083" alt="15" /> 
    <img src="/Photo/Thumbnail/16?size=large" title="walk 125" alt="16" /> 
    <img src="/Photo/Thumbnail/17?size=large" title="001" alt="17" /> 
    <img src="/Photo/Thumbnail/18?size=large" title="002" alt="18" /> 
    <img src="/Photo/Thumbnail/19?size=large" title="003" alt="19" /> 
    <img src="/Photo/Thumbnail/20?size=large" title="004" alt="20" /> 
    <img src="/Photo/Thumbnail/21?size=large" title="005" alt="21" /> 
    <img src="/Photo/Thumbnail/22?size=large" title="006" alt="22" /> 
</div> 

問題: 我想通過當前照片的編號(INT)幻燈片從IMG網址上面的控制器動作,以便我可以在運行時異步顯示來自數據庫的相關信息。如何才能做到這一點?

這裏是位指示操作:

public ActionResult AboutMe(int id) 
    { 
     var myphoto = dbase.Photos.Single(x => x.PhotoId == id); 
     var model = new MeViewModel 
     { 
      UserName =myphoto.UserProfile.UserName, 
      Location =myphoto.UserProfile.Location, 
      ...Continue populating model 

     }; 

     return PartialView(model); 
    } 

回答

0

你可以事後得到裏面的當前幻燈片索引。

在after事件中,您可以使用選項param來引用當前的Slide索引。在下面的例子中,getData將是你的ajax調用。

演示(使用當前索引隱藏/顯示尋呼機):http://jsfiddle.net/lucuma/fg6d4/10/

$('#slideshow').cycle({ 
    prev: $('.controller .prev', this), 
    next: $('.controller .next', this), 
    after: function(currSlideElement, nextSlideElement, options, forwardFlag) { 
     // you can easily adapt this to hide prev on firstslide and next on last slide 
     getData(options.currSlide); 

    } 

}); 
+0

還有別的東西:此網址「(17)」,我怎麼能提取圖片ID在這種情況下發生是否要異步傳遞給控制器​​動作? – user1350968

+0

'$(currentSlideElement).attr('alt')' – lucuma