使用HTML.ActionLink实现一个图片链接

学习ASP.NET MVC 的Razor的语法,尝试把一段普能的图片链接<a ...><img ... />改为HTML.ActionLink实现。

最原始的代码:

 <a href="index.html" class="logo">
    <img src="Content/img/logo/logo4-corporation.png" alt="Logo">
 </a>


Ok,你可以改为:

<a href="@Url.Action("Index", "Home")" class="logo">
    <img src='@Url.Content("~/Content/img/logo/logo4-corporation.png")' />
</a>


下面开始尝试改为Html.ActionLink:

@Html.ActionLink(" ", "Index", "Home", null, new
{
    style = "background: url('" +
    Url.Content("~/Content/img/logo/logo4-corporation.png") + 
    "') no-repeat center right; display:block; height:84px; width:264px;"
})



把样式代码,移至一个css样式文件或是代码块中:

 

posted @ 2016-03-22 14:10  Insus.NET  阅读(1854)  评论(0编辑  收藏  举报