1
我试图创建一个图像助手,该图像助手将呈现图像,但我的助手不会呈现图像。我能看到的所有内容都显示在下面的屏幕截图中。任何人都可以帮助找出原因?请帮忙。这是我的代码。图像助手不会呈现图像(MVC3)
助手类
using System.Configuration;
using System.Web.Mvc;
namespace CMS.Helpers
{
public static class ImageHelper
{
public static string Image(this HtmlHelper htmlHelper, string fileName, string id, string alt, string contentPath)
{
var imgDirectory = ConfigurationManager.AppSettings["imageDirectory"];
var imagePath = string.Format("{0}{1}", imgDirectory, contentPath);
var file = string.Format("{0}{1}", imagePath, fileName);
var img = new TagBuilder("img");
img.MergeAttribute("src", file);
img.MergeAttribute("alt", alt);
return img.ToString(TagRenderMode.SelfClosing);
}
}
}
查看
@Html.Image("TestImage.jpg", "testImg", "TestImg", "/Content/Uploads/MySiteImages")
的Web.Config
<add key="imageDirectory" value="http://localhost:49191"/>
截图
当进入上我看到图像存在浏览器中的图像URL "http://localhost:49191/Content/Uploads/MySiteImages/TestImage.jpg"
。
太感谢你了!这解决了我的问题。 – 2013-05-02 07:21:08