Reputation: 10113
What is the correct way to obtain the URLs of children of the current node while using Umbraco 4.11 in MVC mode? This is what I tried and it keeps returning a blank URL:
@if (CurrentPage.Children().Count() > 0) {
<ul>
@foreach (var child in CurrentPage.Children()) {
<li><a href="@child.Url">@child.Name</a></li>
}
</ul>
}
When that didn't work I resorted to the following:
@Umbraco.NiceUrl(child.Id)
This returns a URL, but it has .aspx extension on it. So my next hack is...
@Umbraco.NiceUrl(child.Id).Replace(".aspx", "")
That's not completely terrible, but I'm wondering if I'm missing something?
Upvotes: 3
Views: 660
Reputation: 6268
Other way to get Only Node Name (Without .aspx) is
@Model.NodeById(@child.Id).urlName
But it will just give Node name without "/"
Upvotes: 0
Reputation: 336
I can't add this as a comment, but there is a way to remove trailing slashes, in umbracoSettings.config:
<addTrailingSlash>true</addTrailingSlash>
Upvotes: 3
Reputation: 4082
You need the NiceUrl() method to generate a valid Url. To get rid of the .aspx extension, you need to set the setting "umbracoUseDirectoryUrls" to true in your web.config file:
<add key="umbracoUseDirectoryUrls" value="true" />
Upvotes: 6