Asp.net mvc 在MVC3中为图像指定src的正确方法

Asp.net mvc 在MVC3中为图像指定src的正确方法,asp.net-mvc,asp.net-mvc-3,razor,Asp.net Mvc,Asp.net Mvc 3,Razor,我就是这样做的 但是这对于Layout.cshtml和部分视图正确吗? 我不应该使用@URl之类的东西来指定源代码吗 我这样问是为了知道正确的方法是什么这可能会打破。以下是正确的做法: <img src="images/img2.jpg" alt="" title="" /> 使用Mvc3Futures\Microsoft.Web.Mvc.dll中的ImageExtensionsHelper函数 你可以在一本书中找到它 公共静态类ImageExtensions { 公共静态MvcH

我就是这样做的

但是这对于Layout.cshtml和部分视图正确吗? 我不应该使用@URl之类的东西来指定源代码吗


我这样问是为了知道正确的方法是什么

这可能会打破。以下是正确的做法:

<img src="images/img2.jpg" alt="" title="" />

使用Mvc3Futures\Microsoft.Web.Mvc.dll中的
ImageExtensions
Helper函数

你可以在一本书中找到它

公共静态类ImageExtensions
{
公共静态MvcHtmlString映像(此HtmlHelper帮助程序,string imageRelativeUrl);
公共静态MvcHtmlString图像(此HtmlHelper帮助程序,字符串imageRelativeUrl,字符串alt);
公共静态MvcHtmlString图像(此HtmlHelper帮助程序、字符串imageRelativeUrl、字符串alt、对象htmlAttributes);
公共静态MvcHtmlString映像(此HtmlHelper帮助程序、字符串imageRelativeUrl、对象htmlAttributes);
公共静态MvcHtmlString映像(此HtmlHelper帮助程序、string imageRelativeUrl、IDictionary htmlAttributes);
公共静态MvcHtmlString映像(此HtmlHelper帮助程序、字符串imageRelativeUrl、字符串alt、IDictionary htmlAttributes);
公共静态TagBuilder图像(字符串imageUrl、字符串alt、IDictionary HtmlatAttribute);
}

还可以查看t4mvc中的强类型内容链接。
<img src="@Url.Content("~/images/img2.jpg")" alt="" title="" />
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);
}