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

[Solved] Sitemap binding issue

1 Answer 97 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.
Bill
Top achievements
Rank 2
Bill asked on 05 Aug 2011, 08:03 PM
I am getting the following error in my _Layout.cshtml file on the BindTo method when trying to bind to a sitemap file. It is an MVC 3 project with Razor.

"You must have SiteMap defined with key "YeagerTech" in ViewData dictionary."

@(Html.Telerik().Menu()
                    .Name("menu")
                    .BindTo("YeagerTech"));











I have a Sitemap file set up named "YeagerTech.sitemap". In it, I have the following xml:
<?xml version="1.0" encoding="utf-8" ?>
<sitemap>
  <siteMapNode title="Home" controller="Home" action="Index">
    <siteMapNode title="Home">
      <siteMapNode controller="Home" action="Testimonials" title="Testimonials" />
      <siteMapNode controller="Home" action="About" title="Contact Us" />
      <siteMapNode controller="Home" action="Payment" title="Make a Payment" />
    </siteMapNode>
    <siteMapNode title="Customer">
      <siteMapNode controller="Customer" action="Index" title="Customer Info" />
    </siteMapNode>
    <siteMapNode title="Sitemap">
      <siteMapNode controller="Home" action="Sitemap" title="Sitemap" />
    </siteMapNode>
  </siteMapNode>
</sitemap>
I have a MenuController set up in my Controllers folder with the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Telerik.Web.Mvc;

namespace YeagerTech.Controllers
{
    public partial class MenuController : Controller
    {
        [PopulateSiteMap(SiteMapName = "YeagerTech", ViewDataKey = "YeagerTech")]
        public ActionResult SiteMapBinding()
        {
            if (!SiteMapManager.SiteMaps.ContainsKey("YeagerTech"))
            {
                SiteMapManager.SiteMaps.Register<XmlSiteMap>("YeagerTech", sitmap => sitmap.LoadFrom("~/YeagerTech.sitemap"));
            }

            return View();
        }
    }
}


The project compiles fine. It's just when I try to run it.

I followed the example at the following link:
http://demos.telerik.com/aspnet-mvc/razor/menu/sitemapbinding


It's not getting into the MenuController obviously, because my HomeController is the default controller. Where do I need to place the code that
exists in my MenuController?

Do I need to put this code on every method in every controller?



1 Answer, 1 is accepted

Sort by
0
Jody
Top achievements
Rank 1
answered on 07 Apr 2012, 08:20 AM
Hi Yeager,
previously I had problem as yours and finally I found the solution by

putting something like this :

namespace smds.web.Controllers
{
    public class HomeController : Controller
    {
	[PopulateSiteMap(SiteMapName = "sample", ViewDataKey = "sample")]
        public ActionResult Index()         {             ViewBag.Message = "Selamat Datang di SMDS Web Application";             if (!SiteMapManager.SiteMaps.ContainsKey("sample"))             {                 SiteMapManager.SiteMaps.Register<XmlSiteMap>("sample", sitmap => sitmap.LoadFrom(@Url.Content("~/sample.sitemap")));             }             return View();         }         public ActionResult About()         {             return View();         }     } }

so the point put in on the home controller no need to create on another controller , because ActionResult Index the first controller hit by the web and voila it's work 

hope this can help , 


RJA,-
Tags
Menu
Asked by
Bill
Top achievements
Rank 2
Answers by
Jody
Top achievements
Rank 1
Share this question
or