如何使用mvc5

时间:2015-11-09 11:03:09

标签: javascript c# asp.net-mvc asp.net-mvc-4 asp.net-mvc-5

View1.cshtml:

          <script>
          var selectedImage;
         function select(image) {
            var images = document.querySelectorAll('img');
            var index = 0, length = images.length;
            for (; index < length; index++) {
                images[index].classList.remove('selected');
            }
            selectedImage = image.id;
            image.classList.add('selected');
            var image = document.getElementById(selectedImage);
            var audioId = image.getAttribute('data-audio')
            var audioElement = document.getElementById(audioId);


                // Check browser supporta
                if (typeof (Storage) !== "undefined") {
                    // Store
                    localStorage.setItem("audiourl", audioElement);

                    // Retrieve
                     document.getElementById("result").innerHTML = localStorage.getItem("audiourl");
                }

       <div>
        @foreach (var item in Model)
        {
        <audio id="audio1" src="@Url.Content(item.Letter_Record)"></audio>
     <audio id="audio2" src="@Url.Content(item.Letter_Word_Record)"></audio>

    <img id="img1" data-audio="audio1" src="@Url.Content(item.Letter_Pic)" alt="" onclick="select(this)"  />

    <img id="img2" data-audio="audio2" src="@Url.Content(item.Letter_Word)" alt="" onclick="select(this)" />
           </div>

这是view1这里是javascript中的一个audiourl,我必须在c#函数中传递view2.cshtml。我必须将视图1中的javascript对象传递给视图2并将其存储为参数。我上面使用的代码是将值存储在本地存储中,但如何在另一个视图的变量中检索此值,以便我可以将其称为视图2的函数?

0 个答案:

没有答案