2012-10-02 39 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