Hey Fuji - yep the var statement is within the foreach.
I've included the whole code below as there is a bit going on elsewhere in the script. There are two separate datatypes which are listed as links right towards the bottom of the script which include the new var statements you kindly suggested.
Basically it saves without any errors but when it is rendered to the page it throws a generic Razor wobbly. I can't immediately see why your addition wouldn't work though.
@inherits umbraco.MacroEngines.DynamicNodeContext @using System.Linq; @using umbraco.cms.businesslogic.datatype; @{ var pagesToList = Model.Children; var clause = "umbracoNaviHide != true"; var queryString = "?page={0}";
Could not seem to make the IsAncestorOrSelf variable work without erroring so decided to go a different route and check the PreValue name against the QueryString.
@foreach (dynamic entry in PreValues.GetPreValues(1075)) { var preValue = entry.Value; var itemUrl = Model.NodeById(Model.Id).Url; if (Request.QueryString["design"] == preValue.Value) { <li><a href="@[email protected]" title="@preValue.Value" class="selected">@preValue.Value</a></li> } else { <li><a href="@[email protected]" title="@preValue.Value">@preValue.Value</a></li> } }
Applying a class to a selected item in Razor
Hey all,
I have the following snippet which lists values from a data type:
How could I determine whether a particular item in the list has been clicked and therefore apply a class="selected" to the <a> tag?
Many thanks,
Mike
Hey Fuji,
Thanks so much for the reply. Looks very logical to me but unfortunately I'm getting a Razor error on the var statement:
you need to add it within the foreach, can you post the whole code ?
Hey Fuji - yep the var statement is within the foreach.
I've included the whole code below as there is a bit going on elsewhere in the script. There are two separate datatypes which are listed as links right towards the bottom of the script which include the new var statements you kindly suggested.
Basically it saves without any errors but when it is rendered to the page it throws a generic Razor wobbly. I can't immediately see why your addition wouldn't work though.
Could not seem to make the IsAncestorOrSelf variable work without erroring so decided to go a different route and check the PreValue name against the QueryString.
Appreciate the help though Fuji. I'm sure there is a better solution but for now this is doing what it should.
is working on a reply...