The name 'Library' does not exist in the current context
Hi All.
Trying to implement a simple image gallery into one of my sites using Razor and I am getting the error "The name 'Library' does not exist in the current context" when trying to save or load the Razor script? I have this script working fine in a WebMatrix Umbraco install I have. However I cannot get it to work in an existing Umbraco 4.7.0 site that I am running on a hosted virtual server. Script below:
@{ //Check the currentpage has a value in the property 'photos' if (Model.HasValue("photos")) { var MediaFolder = Library.MediaById(Model.photos); <div class="flexslider-container"> <div class="flexslider"> <ul class="slides"> @foreach (var photo in MediaFolder.Children) { <li> <img src="@photo.umbracoFile" alt="@photo.Name" /> <p class="flex-caption">@photo.Name</p> </li> } </ul> </div> </div> } }
Still the same issue dawoe even with both statements at the top of my CSHTML files. Was there something changed/added from 4.7.0 to 4.7.1 to include library. I can save and execute the scripts without issue from a 4.7.1 build? I Can't really upgrade the site I need it in though which isn't great.
The name 'Library' does not exist in the current context
Hi All.
Trying to implement a simple image gallery into one of my sites using Razor and I am getting the error "The name 'Library' does not exist in the current context" when trying to save or load the Razor script? I have this script working fine in a WebMatrix Umbraco install I have. However I cannot get it to work in an existing Umbraco 4.7.0 site that I am running on a hosted virtual server. Script below:
@{
//Check the currentpage has a value in the property 'photos'
if (Model.HasValue("photos"))
{
var MediaFolder = Library.MediaById(Model.photos);
<div class="flexslider-container">
<div class="flexslider">
<ul class="slides">
@foreach (var photo in MediaFolder.Children)
{
<li>
<img src="@photo.umbracoFile" alt="@photo.Name" />
<p class="flex-caption">@photo.Name</p>
</li>
}
</ul>
</div>
</div>
}
}
Any Ideas?
Many thanks as always.
Dave.
Do you have the following using directive in your cshtml file : @using umbraco.MacroEngines ?
Thanks for the reply dawoe, however even with that @using added I still receive the same error?
On top of your cshtml file you should have this:
@using umbraco.MacroEngines
@inherits DynamicNodeContext
Still the same issue dawoe even with both statements at the top of my CSHTML files. Was there something changed/added from 4.7.0 to 4.7.1 to include library. I can save and execute the scripts without issue from a 4.7.1 build? I Can't really upgrade the site I need it in though which isn't great.
Suppouse referenced post from Razor snippets could help you. There is mention about Library at top.
Also, instead
Library.MediaById
you can use
Model.MediaById
is working on a reply...