Reputation: 103
I have a section that saves html created with an html editor into a database in the site control panel.
in my html if I insert image with this address "image/Picture1.jpg" using the html editor if there is a image stored at mysite.com/image/picture1.jpg.
Now in a view(razor) I display the stored html content from the database with System.Web.HttpUtility.HtmlDecode
or @Html.Raw(item.Content)
. if this content is shown the in home page like mysite.com it works correctly.
but, if it show it in other area or controller or action the image doesn't show. Because in those areas (like mysite.com/desktop) the image address changes to mysite.com/desktop/image/picture1.jpg.
How do I display this html content without this problem?
Upvotes: 0
Views: 557
Reputation: 93631
The images will always be relative to the page that displays them as you are using a relative URL.
Unless they have an absolute URL mysite.com/image/picture1.jpg
or a root-relative URL /image/picture1.jpg
in the HTML it will not work.
A: You need to enter the URL in the HTML editor as either absolute
mysite.com/image/picture1.jpg
or root-relative:
/image/picture1.jpg
In both cases the browser will search from root of the website, and not just relative to the current page.
Upvotes: 1