I build menu links so I need to know where I am.
The list url looks like: http://domain.com/list
The detail page url looks like: http://domain.com/list/detail
I could search for hardcoded /list part but it will be hardcoded.
I use the PathInfo function below and I always use 0 as parameter:
string PathInfo (int segment)
{
string pathInfo = C1PageRoute.GetPathInfo()??string.Empty;
string[] segments = pathInfo.Split('/');
string stringValue;
stringValue = segments.Skip(segment + 1).FirstOrDefault();
return stringValue;
}
...
// register the use of the path info
C1PageRoute.RegisterPathInfoUsage();
string kuruladi = PathInfo(0);
...
@foreach (var kurul in kurullar)
{
string currentpageitem = "";
if (kurul.KurulAdi == kuruladi)
{
currentpageitem = "current_page_item";
}
<li class="page_item page-item-1167 @currentpageitem">
<a href="@kurul.KurulAdi">@kurul.KurulAdi</a>
</li>
}
Since I don't know where I am (list or detail) PathInfo(0) cannot help. An incorrect example link: http://domain.com/Sample-Detail-Page It should be http://domain.com/Kurul/Sample-Detail-Page
How can I write a much generic code to extract the exact location and then build the correct link? At least am I in list or detail, so I can use 0 or 1 as parameter.
@CurrentPageNode.Url was the missing part:
<li class="page_item page-item-1167 @currentpageitem">
<a href="@CurrentPageNode.Url/@kurul.KurulAdi">@kurul.KurulAdi</a>
</li>