@@ -159,7 +159,7 @@ public static MvcHtmlString Menu(this MvcSiteMapHtmlHelper helper, bool startFro
159
159
/// <returns>Html markup</returns>
160
160
public static MvcHtmlString Menu ( this MvcSiteMapHtmlHelper helper , bool startFromCurrentNode , bool startingNodeInChildLevel , bool showStartingNode , SourceMetadataDictionary sourceMetadata )
161
161
{
162
- ISiteMapNode startingNode = startFromCurrentNode ? GetCurrentNode ( helper . SiteMap ) : helper . SiteMap . RootNode ;
162
+ ISiteMapNode startingNode = startFromCurrentNode ? GetCurrentNode ( helper . SiteMap , true ) : helper . SiteMap . RootNode ;
163
163
return Menu ( helper , startingNode , startingNodeInChildLevel , showStartingNode , Int32 . MaxValue , false , sourceMetadata ) ;
164
164
}
165
165
@@ -204,7 +204,7 @@ public static MvcHtmlString Menu(this MvcSiteMapHtmlHelper helper, bool startFro
204
204
/// <returns>Html markup</returns>
205
205
public static MvcHtmlString Menu ( this MvcSiteMapHtmlHelper helper , bool startFromCurrentNode , bool startingNodeInChildLevel , bool showStartingNode , bool visibilityAffectsDescendants , SourceMetadataDictionary sourceMetadata )
206
206
{
207
- ISiteMapNode startingNode = startFromCurrentNode ? GetCurrentNode ( helper . SiteMap ) : helper . SiteMap . RootNode ;
207
+ ISiteMapNode startingNode = startFromCurrentNode ? GetCurrentNode ( helper . SiteMap , true ) : helper . SiteMap . RootNode ;
208
208
return Menu ( helper , null , startingNode , startingNodeInChildLevel , showStartingNode , Int32 . MaxValue , false , visibilityAffectsDescendants , sourceMetadata ) ;
209
209
}
210
210
@@ -249,7 +249,7 @@ public static MvcHtmlString Menu(this MvcSiteMapHtmlHelper helper, int startingN
249
249
/// <returns>Html markup</returns>
250
250
public static MvcHtmlString Menu ( this MvcSiteMapHtmlHelper helper , int startingNodeLevel , int maxDepth , bool allowForwardSearch , bool drillDownToCurrent , SourceMetadataDictionary sourceMetadata )
251
251
{
252
- ISiteMapNode startingNode = GetStartingNode ( GetCurrentNode ( helper . SiteMap ) , startingNodeLevel , allowForwardSearch ) ;
252
+ ISiteMapNode startingNode = GetStartingNode ( GetCurrentNode ( helper . SiteMap , true ) , startingNodeLevel , allowForwardSearch ) ;
253
253
if ( startingNode == null )
254
254
{
255
255
return MvcHtmlString . Empty ;
@@ -301,7 +301,7 @@ public static MvcHtmlString Menu(this MvcSiteMapHtmlHelper helper, int startingN
301
301
/// <returns>Html markup</returns>
302
302
public static MvcHtmlString Menu ( this MvcSiteMapHtmlHelper helper , int startingNodeLevel , int maxDepth , bool allowForwardSearch , bool drillDownToCurrent , bool visibilityAffectsDescendants , SourceMetadataDictionary sourceMetadata )
303
303
{
304
- ISiteMapNode startingNode = GetStartingNode ( GetCurrentNode ( helper . SiteMap ) , startingNodeLevel , allowForwardSearch ) ;
304
+ ISiteMapNode startingNode = GetStartingNode ( GetCurrentNode ( helper . SiteMap , true ) , startingNodeLevel , allowForwardSearch ) ;
305
305
if ( startingNode == null )
306
306
{
307
307
return MvcHtmlString . Empty ;
@@ -435,7 +435,7 @@ public static MvcHtmlString Menu(this MvcSiteMapHtmlHelper helper, int startingN
435
435
/// <returns>Html markup</returns>
436
436
public static MvcHtmlString Menu ( this MvcSiteMapHtmlHelper helper , int startingNodeLevel , bool startingNodeInChildLevel , bool showStartingNode , int maxDepth , bool allowForwardSearch , bool drillDownToCurrent , SourceMetadataDictionary sourceMetadata )
437
437
{
438
- ISiteMapNode startingNode = GetStartingNode ( GetCurrentNode ( helper . SiteMap ) , startingNodeLevel , allowForwardSearch ) ;
438
+ ISiteMapNode startingNode = GetStartingNode ( GetCurrentNode ( helper . SiteMap , true ) , startingNodeLevel , allowForwardSearch ) ;
439
439
if ( startingNode == null )
440
440
{
441
441
return MvcHtmlString . Empty ;
@@ -490,7 +490,7 @@ public static MvcHtmlString Menu(this MvcSiteMapHtmlHelper helper, int startingN
490
490
/// <returns>Html markup</returns>
491
491
public static MvcHtmlString Menu ( this MvcSiteMapHtmlHelper helper , int startingNodeLevel , bool startingNodeInChildLevel , bool showStartingNode , int maxDepth , bool allowForwardSearch , bool drillDownToCurrent , bool visibilityAffectsDescenants , SourceMetadataDictionary sourceMetadata )
492
492
{
493
- ISiteMapNode startingNode = GetStartingNode ( GetCurrentNode ( helper . SiteMap ) , startingNodeLevel , allowForwardSearch ) ;
493
+ ISiteMapNode startingNode = GetStartingNode ( GetCurrentNode ( helper . SiteMap , true ) , startingNodeLevel , allowForwardSearch ) ;
494
494
if ( startingNode == null )
495
495
{
496
496
return MvcHtmlString . Empty ;
@@ -791,7 +791,7 @@ public static MvcHtmlString Menu(this MvcSiteMapHtmlHelper helper, string templa
791
791
/// <returns>Html markup</returns>
792
792
public static MvcHtmlString Menu ( this MvcSiteMapHtmlHelper helper , string templateName , bool startFromCurrentNode , bool startingNodeInChildLevel , bool showStartingNode , SourceMetadataDictionary sourceMetadata )
793
793
{
794
- ISiteMapNode startingNode = startFromCurrentNode ? GetCurrentNode ( helper . SiteMap ) : helper . SiteMap . RootNode ;
794
+ ISiteMapNode startingNode = startFromCurrentNode ? GetCurrentNode ( helper . SiteMap , true ) : helper . SiteMap . RootNode ;
795
795
return Menu ( helper , templateName , startingNode , startingNodeInChildLevel , showStartingNode , Int32 . MaxValue , false , sourceMetadata ) ;
796
796
}
797
797
@@ -839,7 +839,7 @@ public static MvcHtmlString Menu(this MvcSiteMapHtmlHelper helper, string templa
839
839
/// <returns>Html markup</returns>
840
840
public static MvcHtmlString Menu ( this MvcSiteMapHtmlHelper helper , string templateName , bool startFromCurrentNode , bool startingNodeInChildLevel , bool showStartingNode , bool visibilityAffectsDescendants , SourceMetadataDictionary sourceMetadata )
841
841
{
842
- ISiteMapNode startingNode = startFromCurrentNode ? GetCurrentNode ( helper . SiteMap ) : helper . SiteMap . RootNode ;
842
+ ISiteMapNode startingNode = startFromCurrentNode ? GetCurrentNode ( helper . SiteMap , true ) : helper . SiteMap . RootNode ;
843
843
return Menu ( helper , templateName , startingNode , startingNodeInChildLevel , showStartingNode , Int32 . MaxValue , false , visibilityAffectsDescendants , sourceMetadata ) ;
844
844
}
845
845
@@ -887,7 +887,7 @@ public static MvcHtmlString Menu(this MvcSiteMapHtmlHelper helper, string templa
887
887
/// <returns>Html markup</returns>
888
888
public static MvcHtmlString Menu ( this MvcSiteMapHtmlHelper helper , string templateName , int startingNodeLevel , int maxDepth , bool allowForwardSearch , bool drillDownToCurrent , SourceMetadataDictionary sourceMetadata )
889
889
{
890
- ISiteMapNode startingNode = GetStartingNode ( GetCurrentNode ( helper . SiteMap ) , startingNodeLevel , allowForwardSearch ) ;
890
+ ISiteMapNode startingNode = GetStartingNode ( GetCurrentNode ( helper . SiteMap , true ) , startingNodeLevel , allowForwardSearch ) ;
891
891
if ( startingNode == null )
892
892
{
893
893
return MvcHtmlString . Empty ;
@@ -986,7 +986,7 @@ public static MvcHtmlString Menu(this MvcSiteMapHtmlHelper helper, string templa
986
986
/// <returns>Html markup</returns>
987
987
public static MvcHtmlString Menu ( this MvcSiteMapHtmlHelper helper , string templateName , int startingNodeLevel , bool startingNodeInChildLevel , bool showStartingNode , int maxDepth , bool allowForwardSearch , bool drillDownToCurrent , SourceMetadataDictionary sourceMetadata )
988
988
{
989
- ISiteMapNode startingNode = GetStartingNode ( GetCurrentNode ( helper . SiteMap ) , startingNodeLevel , allowForwardSearch ) ;
989
+ ISiteMapNode startingNode = GetStartingNode ( GetCurrentNode ( helper . SiteMap , true ) , startingNodeLevel , allowForwardSearch ) ;
990
990
if ( startingNode == null )
991
991
{
992
992
return MvcHtmlString . Empty ;
@@ -1047,7 +1047,7 @@ public static MvcHtmlString Menu(this MvcSiteMapHtmlHelper helper, string templa
1047
1047
/// <returns>Html markup</returns>
1048
1048
public static MvcHtmlString Menu ( this MvcSiteMapHtmlHelper helper , string templateName , int startingNodeLevel , bool startingNodeInChildLevel , bool showStartingNode , int maxDepth , bool allowForwardSearch , bool drillDownToCurrent , bool visibilityAffectsDescendants , SourceMetadataDictionary sourceMetadata )
1049
1049
{
1050
- ISiteMapNode startingNode = GetStartingNode ( GetCurrentNode ( helper . SiteMap ) , startingNodeLevel , allowForwardSearch ) ;
1050
+ ISiteMapNode startingNode = GetStartingNode ( GetCurrentNode ( helper . SiteMap , true ) , startingNodeLevel , allowForwardSearch ) ;
1051
1051
if ( startingNode == null )
1052
1052
{
1053
1053
return MvcHtmlString . Empty ;
@@ -1332,6 +1332,20 @@ private static MenuHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SourceMet
1332
1332
/// <param name="selectedSiteMapProvider">the current MVC Site Map Provider</param>
1333
1333
/// <returns></returns>
1334
1334
public static ISiteMapNode GetCurrentNode ( ISiteMap selectedSiteMap )
1335
+ {
1336
+ return GetCurrentNode ( selectedSiteMap , false ) ;
1337
+ }
1338
+
1339
+ /// <summary>
1340
+ /// This determines the deepest node matching the current HTTP context, so if the current URL describes a location
1341
+ /// deeper than the site map designates, it will determine the closest parent to the current URL and return that
1342
+ /// as the current node. This allows menu relevance when navigating deeper than the sitemap structure designates, such
1343
+ /// as when navigating to MVC actions, which are not shown in the menus
1344
+ /// </summary>
1345
+ /// <param name="selectedSiteMapProvider">the current MVC Site Map Provider</param>
1346
+ /// <param name="returnRootNodeIfNotFound">whether to return the root node if the current node is null</param>
1347
+ /// <returns></returns>
1348
+ public static ISiteMapNode GetCurrentNode ( ISiteMap selectedSiteMap , bool returnRootNodeIfNotFound )
1335
1349
{
1336
1350
// get the node matching the current URL location
1337
1351
var currentNode = selectedSiteMap . CurrentNode ;
@@ -1341,11 +1355,12 @@ public static ISiteMapNode GetCurrentNode(ISiteMap selectedSiteMap)
1341
1355
if ( currentNode == null )
1342
1356
{
1343
1357
var url = HttpContext . Current . Request . Url . LocalPath ;
1358
+ var queryString = HttpContext . Current . Request . Url . Query ;
1344
1359
1345
1360
while ( url . Length > 0 )
1346
1361
{
1347
1362
// see if we can find a matching node
1348
- currentNode = selectedSiteMap . FindSiteMapNode ( url ) ;
1363
+ currentNode = selectedSiteMap . FindSiteMapNode ( url + queryString ) ;
1349
1364
1350
1365
// if we get a hit, stop
1351
1366
if ( currentNode != null ) break ;
@@ -1357,6 +1372,13 @@ public static ISiteMapNode GetCurrentNode(ISiteMap selectedSiteMap)
1357
1372
}
1358
1373
}
1359
1374
1375
+ // If the current node is still null, return the root node.
1376
+ // This is the same way the SiteMap.FindSiteMapNode(rawUrl) method worked in v3.
1377
+ if ( currentNode == null && returnRootNodeIfNotFound )
1378
+ {
1379
+ currentNode = selectedSiteMap . RootNode ;
1380
+ }
1381
+
1360
1382
return currentNode ;
1361
1383
}
1362
1384
0 commit comments