Getting a full URL from a SiteMapNode
Hi
I'm making my own MVC navigation bar widget. I'm just beginning, so far it's pretty simple. All I want to do is list the links to each page that should go in the navigation bar.
Controller:
public
class
NavigationBarController : Controller
public
ActionResult Index()
var provider = SiteMapBase.GetSiteMapProvider(
"FrontendSiteMap"
);
var topNavNodes = provider.GetChildNodes(provider.RootNode);
return
View(
"NavigationBar"
, topNavNodes);
@model SiteMapNodeCollection
<
ul
>
@foreach (var baseNode in Model)
<
li
>
<
a
href
=
"@baseNode.Url"
>@baseNode.Title</
a
>
</
li
>
</
ul
>
Hi Kurren,
You can use the Url.Content method that will take a relative Url and returns an absolute Url.
<
ul
>
@foreach (var baseNode in Model)
<
li
>
<
a
href
=
"@Url.Content(baseNode.Ur)"
>@baseNode.Title</
a
>
</
li
>
</
ul
>
Hi Daniel
Thanks for your reply. It worked like a charm.
Kurren
Hi Kurren,
That is great to hear.
Glad I could help.
Kind regards,
Daniel