내 Visual Studio 프로젝트에서 이미지를 저장하는 폴더가 있습니다. 이 이미지의 경로는 SQL Server DB에 저장되어 있으며이 이미지를 뷰에 표시하려고합니다. 지금까지 한 연구에서 HTML 도우미를 만들어야합니다. 헬퍼에게 경로를 전달하여 내보기에서 콘텐츠 표시 아래에 렌더링 할 수 있습니까?ASP MVC 5 이미지 디스플레이
보기
@Html.DisplayFor(modelItem => item.contentDisplay)
도우미
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));
}
}
컨트롤러
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);
모델 내 생각에 (그것이 정말로 올바른 경우)
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; }
어떻게 내가 도우미를 사용할 수 있습니까?
에 표시하는 방법입니다? 샘플 값은 어떻게 생깁니 까? 또한 이미지 저장 디렉토리가 앱에 있습니까? – Shyju