In my Visual studio project, i have a folder where i am storing an Image. The path to this image is stored in the SQL Server DB and im trying to display this image in the view. From the research i have done so far, a HTML helper needs to be created, which i had a go at. How can i pass the path to the helper so that it renders in my view, under content display?
View
@Html.DisplayFor(modelItem => item.contentDisplay)
Helper
public static class CustomHtmlHelper
{
public static IHtmlString Image(this HtmlHelper helper, string src)
{
TagBuilder tb = new TagBuilder("img");
tb.Attributes.Add("src", VirtualPathUtility.ToAbsolute(src));
return new MvcHtmlString(tb.ToString(TagRenderMode.SelfClosing));
}
}
Controller
private dbmb17adtEntities db = new dbmb17adtEntities();
// GET: tbl_Post2
public ActionResult Index()
{
var tbl_Post = db.tbl_Post.Include(t => t.tbl_User);
return View(tbl_Post);
Model
public partial class tbl_Post
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public tbl_Post()
{
this.tbl_Comment = new HashSet<tbl_Comment>();
this.tbl_Tag = new HashSet<tbl_Tag>();
}
public int Id { get; set; }
public string title { get; set; }
public string content { get; set; }
public string contentDisplay { get; set; }
public string tags { get; set; }
public Nullable<System.DateTime> createTime { get; set; }
public Nullable<System.DateTime> updateTime { get; set; }
public Nullable<int> commentCount { get; set; }
public int authorId { get; set; }
public Nullable<int> likeCount { get; set; }
How can i use the helper (if it is indeed correct) in my view?