I would like to share among views the logic for creating an img tag from a mediaPart. I have already created the following razor helper
method:
@helper CreateImgFromMediaPart(dynamic mediaPart, int width = 150)
{
var imgSrc = mediaPart != null ? mediaPart.MediaUrl : string.Empty;
var imgAlt = mediaPart != null ? mediaPart.AlternateText : string.Empty;
<img alt="@imgAlt" src="@imgSrc" />
}
I have tried this by creating an App_Code folder, putting into it a MyHelpers.cshtml file, and putting in that file the above helper method. Unfortunately, we receive the following error:
The name 'MyHelpers' does not exist in the current context.