Javascript函数播放视频Asp.net循环

时间:2015-07-01 16:27:22

标签: c# asp.net-mvc

我想遍历数据库中的一个字段,一个接一个地返回每个字段,所以我使用foreach标记razor视图,如下所示:

    @foreach (var nameurl in Model.ListSplash)

    {
     //returns the url one after another on the console  
 System.Diagnostics.Debug.WriteLine("Count " + nameurl.Url.Length);
        var url = nameurl.Url.Length;

    <script>

        resetVid = function () {
            //get the Video div and replace with the original video source code
            var videoPanel = document.getElementById('vid');
            videoPanel.innerHTML = '<iframe src="//www.youtube.com/embed/@Model.xxxxdisplay.Url" frameborder="0" allowfullscreen></iframe>';
        }

            PlayVid = function () {
                //get the Video div and play new video on button click
                var videoPanel = document.getElementById('vid');
                videoPanel.innerHTML = '<iframe src="//www.youtube.com/embed/@nameurl.Url?autoplay=1&start=0" frameborder="0" allowfullscreen></iframe>';

                //replace video after 8.5 seconds
                //setTimeout(resetVid, 8500);
            }
     </script>
      }

我的挑战是,当在视图中调用javascript方法时,它会不断返回字段中的最后一个数据(假设每个按钮都应该返回数据):

<button onclick="PlayVid()">
                            <img src="~/img/cover1.jpg" alt="people" class="img-circle" />
                     </button>
                    <button onclick="PlayVid()">
                        <img src="~/img/cover2.jpg" alt="people" class="img-circle" />
                    </button>
                    <button onclick="PlayVid()">
                        <img src="~/img/cover3.jpg" alt="people" class="img-circle" />
                    </button>

我希望每个按钮在单击按钮时从表中返回唯一的URL,但最后一个数据会一直返回。 请帮助。

0 个答案:

没有答案