【问题标题】:Redirection to an action with razor by clicking into button通过单击按钮重定向到带有剃刀的动作
【发布时间】:2013-06-18 09:51:22
【问题描述】:

我有一个 asp.net mvc4 应用程序。我必须在其中放置一个带有 url 的 n 图像到一个动作:

<a href="@Html.ActionLink("Retour","Retour","Client")"><img src="~/Content/images/home-icon.png" /></a>

但是出现了无效url的错误。 那么这个错误的原因是什么?如何修复我的代码?

【问题讨论】:

  • 仅使用@Html.ActionLink("Retour",...
  • 怎么样?我需要通过单击按钮来重定向到操作没有一个简单的链接
  • 错误出现在哪里?当你编译或者你的意思是图像不可见?

标签: html asp.net .net asp.net-mvc-3 razor


【解决方案1】:

你可以使用这些方式
方法一:

@Html.ActionLink("Retour","Retour","Client",null, new { @class="background" })

CSS:

a.background
{
    background: url(../Images/image.gif) no-repeat top left;
     display: block;
     width: 150px;
     height: 150px;
     text-indent: -9999px; /* hides the link text */
}

方法二:

<a href='@Url.Action("MyAction", "MyController")'>
    <img src='@Url.Content("~/Content/Images/image.gif")' />
</a>

方法三:

@Html.ActionLink("Retour","Retour","Client" , new {
      style = "background: url('../../Content/Images/image.gif') no-repeat center right;display:block; height:24px; width:24px;"
} )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    • 2012-06-04
    • 1970-01-01
    • 2018-08-07
    • 1970-01-01
    • 1970-01-01
    • 2011-08-07
    相关资源
    最近更新 更多