Error when calling a Controller not defined in Sitemap

Nov 18, 2010 at 10:53 PM

Helllo,

I am new to  MVC SiteMap Provider so please excuse my ignorance.

Customer Controller has index view which contains list of customers as Grid. There are two command buttons on each row - one is to edit users and other to edit locations . Clicking any one of them takes them to CustomerUser or CustomerLocation controller which required customer Id to be passed to its index controller to display users/locations based on it.

The User is not suppose to  navigate directly  to CustomerUser or CustomerLocataion  like /CustomerUser/  .

For this reason I dont have Customer User or CustomerLocation  nodes in sitemap. when I access CustomerUser  from the grid option  MVC SiteMap  helper throws an error "Object reference not set to an instance of an object. 

"

      </div>
    <div id="menu">
         <%= Html.MvcSiteMap().Menu()  %>
    </div>
  <div id="scriptContentHolder">



NullReferenceException: Object reference not set to an instance of an object.]
   MvcSiteMapProvider.SiteMapNodeExtensions.IsInCurrentPath(SiteMapNode current) +107
   MvcSiteMapProvider.Web.Html.SiteMapNodeModelMapper.MapToSiteMapNodeModel(SiteMapNode node, MvcSiteMapNode mvcNode, IDictionary`2 sourceMetadata) +512
   MvcSiteMapProvider.Web.Html.MenuHelper.BuildModel(MvcSiteMapHtmlHelper helper, SiteMapNode startingNode, Boolean startingNodeInChildLevel, Boolean showStartingNode, Int32 maxDepth) +347
   MvcSiteMapProvider.Web.Html.MenuHelper.Menu(MvcSiteMapHtmlHelper helper, SiteMapNode startingNode, Boolean startingNodeInChildLevel, Boolean showStartingNode, Int32 maxDepth) +99
   MvcSiteMapProvider.Web.Html.MenuHelper.Menu(MvcSiteMapHtmlHelper helper) +57

I am sure there is a way  to have the sitemap fully built but not display  it in Menu and not make it Clickable in BreadCrumb. 
Please advise.
Regards,
Shree Menon
Nov 18, 2010 at 11:36 PM

Hello,

I found that Clickable is already defined and is what I was loking for  wrt Breadcrumbs.  Now  I just need to find how to make a node not visible   from MenuHelper.Menu helper.

 

Regards,

 

Shree Menon

Coordinator
Nov 19, 2010 at 9:03 AM

The first post has been resolved in the latest sources on http://mvcsitemap.codeplex.com/SourceControl/list/changesets (check the 2.3.0 branch)

For the second part, check the MvcMusicStore sample, there's an example in there changing behaviour on which HtmlHelper is rendering the node. Here's an example:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MvcSiteMapProvider.Web.Html.Models.SiteMapNodeModel>" %>
<%@ Import Namespace="System.Web.Mvc.Html" %>
<%@ Import Namespace="MvcSiteMapProvider.Web.Html.Models" %>

<% if (Model.IsCurrentNode) { %>
    <%=Model.Title %>
<% } else if (Model.IsInCurrentPath && Model.SourceMetadata["HtmlHelper"].ToString() == "MvcSiteMapProvider.Web.Html.MenuHelper") { %>
    <a href="<%=Model.Url %>"><span style="color: #606060;"><%=Model.Title %></span></a>
<% } else if (Model.IsClickable) { %>
    <a href="<%=Model.Url %>"><%=Model.Title %></a>
<% } else { %>
    <%=Model.Title %>
<% } %>

<%=(Model.MetaAttributes.ContainsKey("bling") ? "(" + Model.MetaAttributes["bling"] + ")" : "")%>
Nov 19, 2010 at 12:25 PM

Maartenba,

Thank you  for assistance . I will look into the MvcMusicStore sample.

Great Product.

Regards,

Shree Menon

Nov 21, 2010 at 4:36 PM

As pointed out by Maartenba, I changed the display template to render <Li> tag only if the Model/Node .Clickable= true. IN what I was doing I could use Clickable attribute but I am sure it is easy enough to introduce new Attribure ( like visible) on sitemap and use it on display template

Shree Menon