How to Display Media Content in Templates using razor
Hi
I searched this site and could not seem to find a method of displaying media content in a template using razor. I found a way by using xslt, but I dont know a thing about xslt, and I am more fimiliar with razor.
So here is a way that works for me using inline razor code.
Note: "contentMediaImage" is the name of your Media Picker field.
<umbraco:Macro runat="server" Language="cshtml"> @inherits umbraco.MacroEngines.DynamicNodeContext @{ if (Model.contentMediaImage != "") { var media = Library.MediaById(Model.contentMediaImage); <img src="@media.umbracoFile" /> } } </umbraco:Macro>
How to Display Media Content in Templates using razor
Hi
I searched this site and could not seem to find a method of displaying media content in a template using razor.
I found a way by using xslt, but I dont know a thing about xslt, and I am more fimiliar with razor.
So here is a way that works for me using inline razor code.
Note: "contentMediaImage" is the name of your Media Picker field.
<umbraco:Macro runat="server" Language="cshtml">
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
if (Model.contentMediaImage != "")
{
var media = Library.MediaById(Model.contentMediaImage);
<img src="@media.umbracoFile" />
}
}
</umbraco:Macro>
is working on a reply...