Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
hi guys,
I am trying to do simple navigatin consisting of two links: next / previous and I am following razor code
@foreach (var item in @Model.DescendantsOrSelf())
{
var linkN = @Model.Next().Url;
var linkP = @Model.Previous().Url;
<a href="@linkN">Next</a>
<a href="@linkP">Previous</a> }
it works fine but when there are no siblings and null is returned there is an error. how to avoid this?
regards,
pikej
You can do something like:
@{ if (@Model.Next() != null) { <a href="@Model.Next().Url">Next</a> } if (@Model.Previous() != null) { <a href="@Model.Previous().Url">Previous</a> } }
thanks a lot Sebastiaan, your code works very well!
Hi!
This is a really good example. I have a question.
I have a structure like this:
Have a look at the Up() and Down() methods as well: http://umbraco.com/follow-us/blog-archive/2011/3/13/umbraco-razor-feature-walkthrough-part-5
Thanks I'll do that. BTW is there a way to get a specific document type using where? Like the example below but for document type.
@
foreach
(var item
in
Model.Children.Where(
"bodyText.Contains(\"cat\")"
))
@item.Name
}
Sure, just use:
Model.Children.Where("NodeTypeAlias == \"cat\"");
I am trying to add previous and next buttons including only a specific nodeTypeAlias, but this isn't working. I get an error.
<umbraco:Macro runat="server" language="cshtml"> <div class="prevNextWrap"> @{ if (@Model.Next() != null) { <a class="prevNext" href="@Model.Next().Url">Next</a> } if (@Model.Previous() != null) && @Model.Where("NodeTypeAlias == \"TwoColumnAdmissionsLeftNav\"") { <a class="prevNext" href="@Model.Previous().Url">Previous</a> } } </div>
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
next and previous buttons
hi guys,
I am trying to do simple navigatin consisting of two links: next / previous and I am following razor code
@foreach (var item in @Model.DescendantsOrSelf())
{
var linkN = @Model.Next().Url;
var linkP = @Model.Previous().Url;
<a href="@linkN">Next</a>
<a href="@linkP">Previous</a> }
it works fine but when there are no siblings and null is returned there is an error. how to avoid this?
regards,
pikej
You can do something like:
thanks a lot Sebastiaan, your code works very well!
Hi!
This is a really good example. I have a question.
I have a structure like this:
Category1
Image1
Image2
Category2
Image1
Image2
Have a look at the Up() and Down() methods as well: http://umbraco.com/follow-us/blog-archive/2011/3/13/umbraco-razor-feature-walkthrough-part-5
Thanks I'll do that. BTW is there a way to get a specific document type using where? Like the example below but for document type.
@
foreach
(var item
in
Model.Children.Where(
"bodyText.Contains(\"cat\")"
))
{
@item.Name
}
Sure, just use:
I am trying to add previous and next buttons including only a specific nodeTypeAlias, but this isn't working. I get an error.
is working on a reply...