asp.net - 在 ActionLink 内添加 div

标签 asp.net css asp.net-mvc asp.net-mvc-3

我有一个显示信息的图 block ,但也需要是一个链接。如果用户单击图 block 上的任意位置,则需要将他们带到适当的操作。

下面是我创建的图像。

enter image description here

HTML

    <div class="tile">
        <div class="tile-text">Runs</div>
        <div class="tile-text details">Manage runs, routes, races, and goals</div>
        <div id="runs" class="tile-text live">You have a four mile run today</div>
    </div>

现在,如果我创建一个 ActionLink,它将创建蓝色图 block ,但我不确定如何获取 ActionLink 内的三个子 div。

我尝试过以下 ActionLink:

@Html.ActionLink("Runs", "Index", "Run", null, new { @class = "tile-text" })

这将创建以下图像:

enter image description here

所以基本上,我如何让图 block 链接到 Action 并且仍然拥有所有三个子 div?

最佳答案

如果需要,您可以在 onclick="window.location.href='link'" tile 上添加 <div> 属性,并使用 cursor: pointer 设置其样式,使其看起来像链接。

示例:

<div class="tile" onclick="window.location.href='link'">
    <div class="tile-text">Runs</div>
    <div class="tile-text details">Manage runs, routes, races, and goals</div>
    <div id="runs" class="tile-text live">You have a four mile run today</div>
</div>

或者,您可以将 tile <div> 设为 <a> 元素,并将其样式设置为 display: block 并包含相应的 widthheight ,然后将其所有子元素设为 <span>display: block

示例:

<style type="text/css">
    .tile, .tile-text { display: block; }
    // You could add width and height to .tile if needed.
    // Also, if you want to put tiles next to each other, inline-block for .tile
    // would be more appropriate.
</style>

<a class="tile" href="link">
    <span class="tile-text">Runs</span>
    <span class="tile-text details">Manage runs, routes, races, and goals</span>
    <span id="runs" class="tile-text live">You have a four mile run today</span>
</a>

关于asp.net - 在 ActionLink 内添加 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10674643/

相关文章:

asp.net - 从 asp.net web 应用程序中删除站点移动母版页

asp.net - 使用 Mono 中的 Microsoft.VisualStudio.Web.targets?

javascript - 加载时,带有资源 View 的 Fullcalendar 无法在 ASP.NET MVC 中工作 - 0x800a01bd - javaScript 运行时错误 : Object doesn't support this action

asp.net-mvc - Elmah 日志文件删除,手动还是有设置?

asp.net - 获取ajax日历扩展器控件的选定日期

c# - asp.net读取excel文件的方法

python - 在 PyCharm 和文本编辑器 (Sublime Text) 中呈现 HTML 之间的差异

javascript - 访问jquery中设置的所有输入元素值属性

javascript - 将视差滚动与 "mouse tracker"相结合

c# - 具有动态内容的多语言网站