Reputation: 437
I'm trying to get a Sitecore 8 project going with MVC and I am getting the following error:
Compiler Error Message: CS0103: The name 'RenderLink' does not exist in the current context
I have as references (from the nuget packages)
I've tried a few things with the views/web.config. Perhaps there are clashes?
<namespaces>
<add namespace="Sitecore.Mvc" />
<add namespace="Sitecore.Data.Items" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="TDSExample.Web" />
<add namespace="TDSExample.Entities.Ids" />
<add namespace="Glass.Mapper.Sc" />
</namespaces>
I've cleared the Sitecore cache. I'm not sure what I've missed. Here is a cut down version of the view/rendering:
@model Glass.Mapper.Sc.Web.Mvc.GlassView
<TDSExample.Entities.Templates.Header.Header>
@using Glass.Mapper.Sc @{ Layout = null; var dataSource = Sitecore.Context.Database.GetItem(Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering.DataSource) ?? Sitecore.Context.Item; }
<h1>@Model.Editable(x => x.Title, dataSource)</h1>
<p>
@Model.Editable(x => x.Subtitle, dataSource)
</p>
@RenderLink(x => x.ReadMoreLink, dataSource, new { @class = "read-more" })
Here is a cut down version of the rendering:
@model Glass.Mapper.Sc.Web.Mvc.GlassView
<TDSExample.Entities.Templates.Header.Header>
@using Glass.Mapper.Sc @{ Layout = null; var dataSource = Sitecore.Context.Database.GetItem(Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering.DataSource) ?? Sitecore.Context.Item; }
<h1>@Model.Editable(x => x.Title, dataSource)</h1>
<p>
@Model.Editable(x => x.Subtitle, dataSource)
</p>
@RenderLink(x => x.ReadMoreLink, dataSource, new { @class = "read-more" })
The test fields rendering just fine. I must be missing a reference somewhere. Putting "@using Glass.Mapper.Sc" or "@using Glass.Mapper.Sc/Mvc" stops VS highlighting it as an error. I just can't see what I've missed. Any help is appreciated.
Upvotes: 1
Views: 1951
Reputation: 1155
change this
@model Glass.Mapper.Sc.Web.Mvc.GlassView<TDSExample.Entities.Templates.Header.Header>
into this
@inherits Glass.Mapper.Sc.Web.Mvc.GlassView<TDSExample.Entities.Templates.Header.Header>
And access the methods on the view instead of the model:
@Editable(m => m.Title)
@RenderLink(m => m.ReadMoreLink)
<!--this should work as well for links-->
@Editable(m => m.ReadMoreLink)
Added bonus: you should not have to set the layout to null. Make sure you do not have a _ViewStart.cshtml which could cause this.
Upvotes: 3