Reputation: 6029
I have a view which display information about a store, at the bottom of this view is a partial view which renders particular promotions for that store in question.
On this view I render the logo for the given store using the below snippet
<div class="controls">
<img src="data:image;base64,@System.Convert.ToBase64String(Model.RetailerImage)" width="80" height="80" />
</div>
Now when I run it the partial view that loads the promotions throws an error
An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code Additional information: Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.
My partial at the bottom of the view
<fieldset class="well">
@Html.Action("ListRetailerPromotions", "Promotion", Model)
</fieldset>
which calls this controller
[AuthorizeRolesAttribute(RoleType.Retailer, RoleType.Administrator)]
public ActionResult ListRetailerPromotions(Retailer retailer)
{
PromotionViewModel pvm = new PromotionViewModel
{
RetailerId = retailer.RetailerID,
Promotions = UnitOfWork.Promotion.GetPromotionsForRetailer(retailer.RetailerID).ToList()
};
return PartialView(pvm);
}
But when I get the yellow screen of death as some would say the error message is displayed as
The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
But if I comment the partial view out all works as exspected.
UPDATE I got it to work by setting the RetailerImage to null after is has been referenced as follows
<div class="control-group">
<label class="control-label" for="WebAddress">
Preview
</label>
<div class="controls">
<img src="data:image;base64,@System.Convert.ToBase64String(Model.RetailerImage)" width="80" height="80" />
</div>
</div>
{
Model.RetailerImage = null;
}
</div>
Which is a revolting solution I have to admit.
Upvotes: 2
Views: 1099
Reputation: 11330
Try using Raw
on your image string
@System.Convert.ToBase64String(@Html.Raw(Model.RetailerImage))
If you see the error message, it complains about non-base 64 characters.
This means the framework has HTML encoded the contents of Model.RetailerImage
. One way of preventing this default behavior is to use the Raw
feature.
Upvotes: 1