听取keyPressed事件,Razor

时间:2016-04-20 18:59:03

标签: javascript razor asp.net-ajax

<body>
<table align="center" width="100%" height="100%">
    <tr>
        <td align="center" id="previousPhoto">
            @if (Model.HasPreviousPhoto)
            {
                if (Model.CurrentPhotoIndex == 0)
                {
                        <a href="@HrefHelper.ToPhoto(Model.Title, Model.CurrentPageIndex - 1, maxPhotosOnThePage)">
                            <section class="navSection">
                                <img class="previousPhoto" src="@Url.Content("~/Content/Icons/arrows.png")" />
                            </section>
                        </a>

                    }
                    else
                    {
                        <a href="@HrefHelper.ToPhoto(Model.Title, Model.CurrentPageIndex, Model.CurrentPhotoIndex - 1)">
                            <section class="navSection">
                                <img class="previousPhoto" src="@Url.Content("~/Content/Icons/arrows.png")" />
                            </section>
                        </a>
                    }
            }
            else
            {
                <section class="navSection"></section>
            }
        </td>
        <td class="photoPlaceholder" align="center">
            <section class="photoSection">
                <img src="@Model.CurrentPhoto.GenerateSrcHTML()" />
            </section>
        </td>
        <td align="center" id="nextPhoto">
            @if (Model.HasNextPhoto)
            {
                if (Model.CurrentPhotoIndex == maxPhotosOnThePage)
                {
                        <a href="@HrefHelper.ToPhoto(Model.Title, Model.CurrentPageIndex + 1, 0)">
                            <section class="navSection">
                                <img src="@Url.Content("~/Content/Icons/arrows.png")" />
                            </section>
                        </a>
                }
                else
                {
                        <a href="@HrefHelper.ToPhoto(Model.Title, Model.CurrentPageIndex, Model.CurrentPhotoIndex + 1)">
                            <section class="navSection">
                                <img src="@Url.Content("~/Content/Icons/arrows.png")" />
                            </section>
                        </a>
                }
            }
            else
            {
                <section class="navSection"></section>
            }
        </td>
    </tr>
</table>

现在我需要听左/右箭头keydown事件并触发与这些链接相同的动作。据我了解,这可以在没有JS帮助的情况下完成,对吧?我是ASP.NET的新手,尤其是JS,所以你们有人能告诉我上面描述的最佳方法吗?

1 个答案:

答案 0 :(得分:0)

您需要在视图中添加一段js

APR01FRL.csv <- 1
JAN06FRL.csv <- 2
JUL03FRL.csv <- 3

(function(){
  for (old_name in ls(pos = .GlobalEnv)){
    new_name <- paste(
      substr(old_name, 1, 3), 
      substr(old_name, 4, 5), 
      sep = "-")
    assign(x = new_name, value = get(old_name, pos = .GlobalEnv), pos = .GlobalEnv)
    rm(list = old_name, pos = .GlobalEnv)
  }
})()

print(data.frame(name = ls(), value = get(ls())))