5

我正在为使用 MVC (4) 的 Razor 语法而苦苦挣扎,希望能找到可以帮助我解决问题的人。

我想要一个可点击的徽标(图像)并创建了以下代码。除了两件事之外,这有效。我没有看到图像显示,其次,当在另一个控制器中时,路由出错(http4 错误)。

这就是我现在的做法:

剃刀:

<h1>@Html.ActionLink("siteHeader", "Index", null, new { @class = "site-logo"})</h1>

或者

<h1>@Html.ActionLink("siteHeader", "Index", "Home", new { @class = "site-logo"})</h1>

例如,当在不同的控制器(帐户/购物车/等)中并单击徽标时,会导致 404。

CSS:

/网站标题标志/

a.site-logo  {     
 background: url(images/Solosoft.png) no-repeat top left;
 display: block;       
 width: 100px;       
 height: 100px;       
 text-indent: -9999px;  /*hides the link text*/ 
  } 

提前致谢。

4

3 回答 3

2

试试这个:

@Html.ActionLink("siteHeader", "Index", "Home", null, new { @class = "site-logo"})

这是:

public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper,
    string linkText,
    string actionName,
    string controllerName,
    Object routeValues,
    Object htmlAttributes
)

链接:msdn

于 2012-10-02T13:16:48.143 回答
1

我得到了问题的原因!

我们的编码没有问题,问题是有一个类覆盖了我们的图像集

Site.css 中有这行

.site-title a, .site-title a:hover, .site-title a:active {
    *background: none;* <=comment this out and the bg will show or remove the .site-title a
    color: #c8c8c8;
    outline: none;
    text-decoration: none;
}

希望能帮助到你

于 2013-04-04T08:14:05.860 回答
0

wizzardz说的是正确的。自定义 css 文件中的背景样式被 site.css 中的样式覆盖。

试试这个,!important- 用于优先显示网页中的样式。

在您的 custom.css 页面中,

a.site-logo  {     
     background: url(images/Solosoft.png) no-repeat top left **!important**;
     display: block;       
     width: 100px;    
     height: 100px;       
     text-indent: -9999px;  /*hides the link text*/ 
} 

无需更改 site.css 中的任何内容

于 2013-06-27T13:08:36.403 回答