Reputation: 12736
I'm trying to create image paths (in the src attribute) that are relative to the application root through XSLT.
I want this in the src attribute:
<img src="@Url.Content("~/Content/images/image.svg")" />
And if I insert this manually into the View files, it works fine. But I need to create the files by XSLT, since there are hundreds of them, created from XML. However, the XSLT will not let me insert the quotation marks, it escapes them with #34;
So is there any way to do this? How can I refer to the application root without this, and automatically get this path in XSLT?
I cannot use relative paths either, because due to the structure of the content, one controller action needs to be able to serve lots of different views found in a specific folder structure, based on id...
EDIT:
Actually, now I just tried
<img src="/Content/images/image.svg" />
and that worked fine! If I inspected the image path in the browser, it does get the application root concatenated with the string in the src... So how come everyone seems to be recommending you use @Url.Content()?
EDIT:
To clarify, the problem is getting this into an attribute in XSLT, with nested quotes. I assume this will be impossible, because it is not allowed in XML, but I need a workaround if anyone can think of it.
Upvotes: 1
Views: 2724
Reputation: 243569
Use:
<img src='@Url.Content("~/Content/images/image.svg")' />
Upvotes: 2