I have been googlin' for a long while and have not quite found what I need. This is our scenario.
We have an MVC4 app with Razor. On one screen we are using the Telerik Editor control to save text and images. These are formatted as HTML and stored in the database. The images are stored as byte[] data and the html src "path" is updated with the distinct file name.
Later a user comes and wants to view the data. Because any images are stored in the database, I thought I could use the example found here Convert Byte Array to image and display in Razor View and I would update the tag in the HTML with the tag with a Url.Action and then render all that HTML to the screen.
A sample of my dynamically generated html code after the image tag is replaced is
<p>testing the image blah</p><p><img src="@Url.Action("getImg", "Responses", new { id = 1 }) " alt="Response Image" /> </p>
BUT If I use HTML.Raw(Text), it does not process the image. If I just copy that image tag right into the view, works great.
My question is, how can I render dynamically created HTML with Razor syntax code on a View properly?
*************** more details ***********
A few more details to help clarify what I'm doing. I have two models Response and ResponseImages.
public class Response : TrackableBase
{
[Key]
public int ResponseId { get; set; }
public string Subject{ get; set; }
[MaxLength]
public string Text { get; set; }
public virtual ICollection<ResponseImage> ResponseImages { get; set; }
}
public class ResponseImage : TrackableBase
{
[Key]
public int ResponseImageId { get; set; }
public int ResponseId { get; set; }
[ForeignKey("ResponseId")]
public virtual Response Response { get; set; }
public string FilePath { get; set; }
public string FileName { get; set; }
public string FileExtension { get; set; }
public byte[] Image {get; set;}
}
Response.Text stores HTML from the Telerik editor. I use HTMLAgilitypack to loop through all images in the HTML and from these I create the ResponseImage records, with the ResponseImage.FilePath being what I use as the link back to the HTML code stored in Response.Text (all images are updated with a distinct name/path).
On my Details.cshtml screen I want to view the details of the Response.Text. From the database my Response.Text looks like this:
<p>hjjk</p><p>
<img alt="" height="144" src="/Content/Editor_Images/UserFiles/JKULBIDA/Images/Koala_635019802303066655.jpg" width="164"></p>
BUT, because I am storing images in the database and not the file system, I again use HTMLAgility pack and update all of the image tags with the Razor syntax for using @Url.Action. My new HTML looks like this
<p>hjjk</p><p><img src="@Url.Action("getImg", "Responses", new { id = 4 }) " alt="Response Image" /> </p>
FINALLY, on my View, I want to display my data, but also have the HTML formatted properly. So I call @Html.Raw(Model.Text) and my image tag doesn't work :(
***** end of update ****
Thanks in advance, as I'm super stuck on this.