2012-10-02 45 views
5

我正在用MVC(4)的Razor语法挣扎,希望能够找到能够帮助我的人,并提供一个好的工作解决方案。如何使用MVC(4)创建(图像)标题徽标(4)

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

这是多么我已经做到了现在:

剃刀:

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

OR

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

例如当在不同的控制器(帐号/购物车/等),并单击标志,它会导致404

CSS:

/网站HeaderLogo/

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*/ 
    } 

谢谢提前。

回答

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

+0

好,感谢名单。我几乎在那里:P现在,我只需要找出为什么我没有看到实际的图像。 – RocketRon

+0

@ user1714323在浏览器和网络选项卡上打开开发工具,我想,你会看到404错误。检查你的URL路径,现在你试图找到控制器'文件夹'中的图像,如'/ Home/images/Solosoft.png' – webdeveloper

+0

感谢您的支持。图像的问题是我必须在CSS中正确设置测量。我现在起来跑步了。 – RocketRon

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; 
} 

希望它有助于

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