This is a migrated thread and some comments may be shown as answers.

Error CS1026 When using Menu with MvcSiteMapProvider

3 Answers 105 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sid
Top achievements
Rank 1
Sid asked on 21 Apr 2011, 07:10 PM
Good Morning,

I'm using the MvcSiteMapProvider in my application and am seeing Error CS1026 when viewing in browser.  Here's the code I've written thus far:

View (MenuPartial):
@using Telerik.Web.Mvc.UI;
@using MvcSiteMapProvider;
  
@(Html.Telerik().Menu()
    .Name("Menu")
        .BindTo(Html.MvcSiteMap().Provider.RootNode.ChildNodes,
            mappings => mappings.For<MvcSiteMapNode>(binding => binding
                .ItemDataBound((item, node) =>
                {
                    item.Text = node.Title;
                    item.ActionName = node.Action;
                    item.ControllerName = node.Controller;
                })
                    .Children(node => node.ChildNodes)))
        .Render();
  
)

Menu Controller:
using System.Web.Mvc;
using Telerik.Web.Mvc;
  
namespace Veehco.Controllers
{
    public partial class MenuController : Controller
    {
        [PopulateSiteMap(SiteMapName = "Veehco", ViewDataKey = "Veehco")]
          
        public ActionResult SiteMapBinding()
        {
            if (!SiteMapManager.SiteMaps.ContainsKey("Veehco"))
            {
                SiteMapManager.SiteMaps.Register<XmlSiteMap>("Veehco", sitemap => sitemap.LoadFrom("~/Veehco.sitemap"));
            }
            return View();
        }
    }
}

Global.asax:
protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
  
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            SiteMapManager.SiteMaps.Register<XmlSiteMap>("Veehco.sitemap", sitemap => sitemap.Load());
        }

Can anyone identify the source of the compliation error?  Note that the error message states ") expected".  However, intellisense didn't pickup any errors and the solution built successfully. 

Thanks much for your help and guidance.
Sid

3 Answers, 1 is accepted

Sort by
0
Thijs
Top achievements
Rank 1
answered on 22 Apr 2011, 03:36 PM
Hi, i hope i know what you need to change in order to solve the issue you are having. Change the menu code in your view by the following.

@{Html.Telerik().Menu()
    .Name("Menu")
        .BindTo(Html.MvcSiteMap().Provider.RootNode.ChildNodes,
            mappings => mappings.For<MvcSiteMapNode>(binding => binding
                .ItemDataBound((item, node) =>
                {
                    item.Text = node.Title;
                    item.ActionName = node.Action;
                    item.ControllerName = node.Controller;
                })
                    .Children(node => node.ChildNodes)))
        .Render();
  
}
0
Sid
Top achievements
Rank 1
answered on 22 Apr 2011, 05:12 PM
Thijs,

Thanks for your help.  As an old VB guy, I often confuse parenthesis () for curly brackets {} which was the root cause of my issue.  The compilation error is resolved.  However, I only see two nodes of my sitemap now.  Here's the full mvc.sitemap:
<?xml version="1.0" encoiding="utf-8" ?>
<mvcSiteMap xmlns="Http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="true">
<mvcSiteMapNode title="Home" controller="Home" action="Index">
<mvcSiteMapNode title="About" controller="Home" action="About">
<mvcSiteMapNode title="Contact" controller="Home" action="Contact"/>
</mvcSiteMapNode>
<mvcSiteMapNode title="Borrower" controller="Borrower" action="Index">
<mvcSiteMapNode title= "Sign Up" controller="Borrower" action="Create"/>
</mvcSiteMapNode>
<mvcSiteMapNode title="Investor" controller="Investor" action="Index">
<mvcSiteMapNode title="Sign Up" controller="Investor" action="Create"/>
</mvcSiteMapNode>
<mvcSiteMapNode title="Dealer" controller="Dealer" action="Index">
<mvcSiteMapNode title="Sign Up" controller="Dealer" action="Create"/>
</mvcSiteMapNode>
</mvcSiteMap>

What do I need to do to the sitemap or the Menu to expose the other nodes?

Thanks,
Sid
0
Thijs
Top achievements
Rank 1
answered on 23 Apr 2011, 10:33 AM
Sid,

Your welcome, glad you could finally see a part of your sitemap.
Could you please tell me which nodes you see of your sitemap?

Anyways i copied your pasted code in to a web.sitemap i had and it gave a couple of errors. i corrected them:

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="Http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="true">
  <mvcSiteMapNode title="Home" controller="Home" action="Index">
    <mvcSiteMapNode title="About" controller="Home" action="About">
      <mvcSiteMapNode title="Contact" controller="Home" action="Contact"/>
    </mvcSiteMapNode>
    <mvcSiteMapNode title="Borrower" controller="Borrower" action="Index">
      <mvcSiteMapNode title= "Sign Up" controller="Borrower" action="Create"/>
    </mvcSiteMapNode>
    <mvcSiteMapNode title="Investor" controller="Investor" action="Index">
      <mvcSiteMapNode title="Sign Up" controller="Investor" action="Create"/>
    </mvcSiteMapNode>
    <mvcSiteMapNode title="Dealer" controller="Dealer" action="Index">
      <mvcSiteMapNode title="Sign Up" controller="Dealer" action="Create"/>
    </mvcSiteMapNode>
  </mvcSiteMapNode>
</mvcSiteMap>

Thijs 
Tags
Menu
Asked by
Sid
Top achievements
Rank 1
Answers by
Thijs
Top achievements
Rank 1
Sid
Top achievements
Rank 1
Share this question
or