I upload a selected image to wwwroot folder. That works.
I return the Razor Page with a ViewData containing the path. That doesn’t work.
This is what shows when I debug ViewData in Immediate debug window:
?ViewData["Uploaded"]
"~/images/DanceImages/bulltrout.jpg"
If I paste that path exactly into an img tag, it works:
<img src="~/images/DanceImages/bulltrout.jpg" alt="" />
But if I try to reference the ViewData[“Uploaded”] on the Razor page, I just get the path displayed:
html:
@ViewData["Uploaded"].ToString()
displays this string:
~/images/DanceImages/bulltrout.jpg
So I tried using url.content syntax :
@Url.Content(ViewData["Uploaded"].ToString())
and I get the path displayed again but without the “~/”
To summarize:
The actual string cut from inside the ViewData object when used with <img tag works.
Screenprint below has hardcoded path that works.
Then next is url.content result
Then finally img tag result
I can’t seem to reference the ViewData[“Uploaded”] on the Razor page.