I am trying to replace the infamous "your logo here" in _Layout.cshtml for the ASP.NET MVC4 Web Application. The following works (works as in the image is displayed) for the main page (Home view) but not on the contact view (no image but the action works). I need this to work both in the development environment as well as the production environment.
< p class="site-title">@Html.ActionLink(" ", "Index", "Home", new
{
style = "background: url('./Images/login_sm.bmp') no-repeat center right;
display:block; height:84px; width:264px;"
})
</ p>
Images are always relative to the location of the current CSS.
If you are using inline CSS you should use url helpers:
@Html.ActionLink(
" ",
"Index",
"Home",
null ,
new {
style = "background: url('" + Url.Content("~/images/login_sm.bmp") + "') no-repeat center right; display:block; height:84px; width:264px;"
}
)
or if you decide to define a CSS class:
@Html.ActionLink(
" ",
"Index",
"Home",
null ,
new {
@class = "mylink"
}
)
where you have defined the .mylink
rule in ~/content/Site.css
:
.mylink {
background: url('../images/login_sm.bmp') no-repeat center right;
display: block;
height: 84px;
width: 264px;
}
The best way you can do as below
@Html.Raw(@Html.ActionLink("[replacetext]", "Index", "Home").ToHtmlString().Replace("[replacetext]", "<img src=\"/assets/img/logo.png\" ... />"))
which perfectly working
You can use this
<a href='@Url.Action("action", "Controller")'>
<img src='@Url.Content("~/images/imageName.png")' /></a>
this is working fine and it works similar to @Html.ActionLink("linkName","action","Controller")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With