I wondered if it is possible to show picture in a view without calling an action. The picture is displayed by using the following Razor code:
<img class="photo" src="@Url.Action("GetImage", "Home", new { id = @Model.Id })" />
But retrieving picture from server requires an additional request.
Is it possible to “deploy” image in ViewBag and show it in view without calling server?
Thanks,
You could use the Data URI scheme. But be careful as it might not be supported by all browsers.
Example:
where
srcattribute of the image contains the Base64 encoded image that could come from ViewBag or a view model.