Why doesnt this code print "NewString" value? It prints the text only (as in the code itself) but not the value (in this case the destination once the , is stripped off)?
@foreach (var childPage in Model.Children.Where("Visible"))
{
<li>
<a href="@childPage.Url">@childPage.Name</a>
var myString = @childPage.Destination.ToString();
var NewString = myString.Split(',').Last();
New string is <span>NewString</span>
@* if the current page has any children, where the property umbracoNaviHide is not True *@
@if (childPage.Children.Where("Visible").Any())
{
@* Call our helper to display the children *@
@childPages(childPage.Children )
}
</li>
}
Try to move your variables before the li tag. I have not tested it but this is what I would type:
@foreach (var childPage in Model.Children.Where("Visible"))
{
var myString = @childPage.Destination.ToString();
var NewString = myString.Split(',').Last();
<li>
<a href="@childPage.Url">@childPage.Name</a>
New string is <span>@NewString</span>
@* if the current page has any children, where the property umbracoNaviHide is not True *@
@if (childPage.Children.Where("Visible").Any())
{
@* Call our helper to display the children *@
@childPages(childPage.Children)
}
</li>
}
Razor Syntax issue
Why doesnt this code print "NewString" value? It prints the text only (as in the code itself) but not the value (in this case the destination once the , is stripped off)?
Change this line of code with the of following:
I tried that and get the error
The name 'NewString' does not exist in the current context
Try to move your variables before the li tag. I have not tested it but this is what I would type:
Perhaps you answered your own question.
The code
@childPage.Destination.ToString()
may instead be@childPage.Destination.Value.ToString()
Or something along those lines.
is working on a reply...