Reputation: 5546
I have the following code:
<img src="images/img2.jpg" alt="" title="" />
Is this correct for Layout.cshtml
and partial views?
Should I instead specify the source using something like @URl
?
Upvotes: 4
Views: 222
Reputation: 14874
Use the ImageExtensions
Helper function from the Mvc3Futures\Microsoft.Web.Mvc.dll.
You can find it in NuGet repository.
public static class ImageExtensions
{
public static MvcHtmlString Image(this HtmlHelper helper, string imageRelativeUrl);
public static MvcHtmlString Image(this HtmlHelper helper, string imageRelativeUrl, string alt);
public static MvcHtmlString Image(this HtmlHelper helper, string imageRelativeUrl, string alt, object htmlAttributes);
public static MvcHtmlString Image(this HtmlHelper helper, string imageRelativeUrl, object htmlAttributes);
public static MvcHtmlString Image(this HtmlHelper helper, string imageRelativeUrl, IDictionary<string, object> htmlAttributes);
public static MvcHtmlString Image(this HtmlHelper helper, string imageRelativeUrl, string alt, IDictionary<string, object> htmlAttributes);
public static TagBuilder Image(string imageUrl, string alt, IDictionary<string, object> htmlAttributes);
}
Upvotes: 2
Reputation: 58444
This will probably gonna break. The below one is the right way of doing it :
<img src="@Url.Content("~/images/img2.jpg")" alt="" title="" />
Upvotes: 4