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.
Mike Beeler's answer worked. This is the web.config that I added to my Views folder.
Have you added the dll reference to the web.config in the views folder? This is what is used to resolve razor specific helper/definitions.