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

[Solved] Error binding Tabstrip to sitemap: Where does sitemap get loaded into viewdata?

3 Answers 188 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
William Brown
Top achievements
Rank 1
William Brown asked on 16 Jun 2010, 05:35 PM
Hello,

On my previous post Georgio provided a sample app that has a tabstrip bound to a sitemap, registered in global.asax.cs and bound in the sitemaster (see http://www.telerik.com/community/forums/aspnet-mvc/tabstrip/can-you-put-the-tabstrip-in-a-master-page.aspx#1235366).  When I moved the code to my project, I added this to the global.asax.cs:

 

protected void Application_Start()

 

{

 

// register the sitemaps into SiteMapManager.SiteMaps collection

 

 

SiteMapManager.SiteMaps.Register<XmlSiteMap>("AdminSitemap", sitmap => sitmap.LoadFrom("~/Sitemaps/Admin.sitemap"));
....

and this to my view:

 

<%

= Html.Telerik()

 

.TabStrip()

.Name(

"TabStrip")

 

.BindTo(

"AdminSitemap")

 

%>

 

and this to the bottom of my site.master before the end body tag:

 

<% Html.Telerik().ScriptRegistrar().OnDocumentReady(() =>

{

%>

    jQuery('#TabStrip').bind('dataBound', function(){Sys.Mvc.FormContext._Application_Load()})

<%

    })

.    Render();

%>

 

When I run this project that looks to me like the sample project, I get:

Server Error in '/' Application.

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

What am I missing?  Where does the AdminSitemap get loaded into the viewdata for the home view?

Thanks,

Bill

3 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 17 Jun 2010, 09:15 AM
Hello William,

Unfortunately it is hard to determine what could be the reason for the depicted issue. In order to progress with the investigation of the problem, I will ask you to send us a simple test project which reproduces the described erroneous behavior.

Regards,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Eric
Top achievements
Rank 1
answered on 06 Aug 2010, 06:48 PM
I am having the same issue with the code that was posted for putting the tabstrip into the site.master.  Everything I've tried gives me the same error as above.

Anyone have a solution?

Eric
0
Chris Axe
Top achievements
Rank 1
answered on 06 Aug 2010, 11:23 PM
I'm using the comercial version and got this error but replaced HtmlHelperExtension with the following


// (c) Copyright 2002-2010 Telerik

// This source is subject to the GNU General Public License, version 2

// See http://www.gnu.org/licenses/gpl-2.0.html.

// All other rights reserved.

using Telerik.Web.Mvc.UI;

using Telerik.Web.Mvc;

 

namespace Local.Web.Mvc.UI

{

    using System.Collections.Generic;

    using System;

    using System.Web;

    using System.Web.Mvc;

    using System.Web.Mvc.Html;

    using System.Web.Routing;

    using System.Linq;

    using System.Linq.Expressions;

    using System.ComponentModel.DataAnnotations;

    using Telerik.Web.Mvc.Infrastructure;

 

    /// <summary>

    /// HTMLHelper extension for providing access to <see cref="ViewComponentFactory"/>.

    /// </summary>

    public static class HtmlHelperExtension

    {

        private static readonly string Key = typeof(ViewComponentFactory).AssemblyQualifiedName;

 

        /// <summary>

        /// Gets the Telerik View Component Factory

        /// </summary>

        /// <param name="helper">The helper.</param>

        /// <returns>The Factory</returns>

        public static ViewComponentFactory Telerik(this HtmlHelper helper)

        {

            Guard.IsNotNull(helper, "helper");

 

            ViewContext viewContext = helper.ViewContext;

            HttpContextBase httpContext = viewContext.HttpContext;

            ViewComponentFactory factory = httpContext.Items[Key] as ViewComponentFactory;

 

            if (factory == null)

            {

                IServiceLocator locator = ServiceLocator.Current;

 

                IWebAssetItemMerger assetItemMerger = locator.Resolve<IWebAssetItemMerger>();

                ScriptWrapperBase scriptWrapper = locator.Resolve<ScriptWrapperBase>();

                IClientSideObjectWriterFactory clientSideObjectWriterFactory = locator.Resolve<IClientSideObjectWriterFactory>();

 

                StyleSheetRegistrar styleSheetRegistrar = new StyleSheetRegistrar(new WebAssetItemCollection(WebAssetDefaultSettings.StyleSheetFilesPath), viewContext, assetItemMerger);

                ScriptRegistrar scriptRegistrar = new ScriptRegistrar(new WebAssetItemCollection(WebAssetDefaultSettings.ScriptFilesPath), new List<IScriptableComponent>(), viewContext, assetItemMerger, scriptWrapper);

 

                StyleSheetRegistrarBuilder styleSheetRegistrarBuilder = new StyleSheetRegistrarBuilder(styleSheetRegistrar);

                ScriptRegistrarBuilder scriptRegistrarBuilder = new ScriptRegistrarBuilder(scriptRegistrar);

 

                factory = new ViewComponentFactory(helper, clientSideObjectWriterFactory, styleSheetRegistrarBuilder, scriptRegistrarBuilder);

 

                httpContext.Items[Key] = factory;

            }

            else

            {

                factory.HtmlHelper = helper;

            }

 

            return factory;

        }

 

#if MVC2

 

        /// <summary>

        /// Gets the Telerik View Component Factory

        /// </summary>

        /// <param name="helper">The helper.</param>

        /// <returns>The Factory</returns>

        public static ViewComponentFactory<TModel> Telerik<TModel>(this HtmlHelper<TModel> helper)

        {

            Guard.IsNotNull(helper, "helper");

 

            ViewContext viewContext = helper.ViewContext;

            HttpContextBase httpContext = viewContext.HttpContext;

 

            ViewComponentFactory<TModel> factory = httpContext.Items[Key] as ViewComponentFactory<TModel>;

 

            if (factory == null)

            {

                IServiceLocator locator = ServiceLocator.Current;

 

                IWebAssetItemMerger assetItemMerger = locator.Resolve<IWebAssetItemMerger>();

                ScriptWrapperBase scriptWrapper = locator.Resolve<ScriptWrapperBase>();

                IClientSideObjectWriterFactory clientSideObjectWriterFactory = locator.Resolve<IClientSideObjectWriterFactory>();

 

                StyleSheetRegistrar styleSheetRegistrar = httpContext.Items[StyleSheetRegistrar.Key] as StyleSheetRegistrar ??

                                                          new StyleSheetRegistrar(new WebAssetItemCollection(WebAssetDefaultSettings.StyleSheetFilesPath), viewContext, assetItemMerger);

                ScriptRegistrar scriptRegistrar = httpContext.Items[ScriptRegistrar.Key] as ScriptRegistrar ??

                                                          new ScriptRegistrar(new WebAssetItemCollection(WebAssetDefaultSettings.ScriptFilesPath), new List<IScriptableComponent>(), viewContext, assetItemMerger, scriptWrapper);

 

                StyleSheetRegistrarBuilder styleSheetRegistrarBuilder = new StyleSheetRegistrarBuilder(styleSheetRegistrar);

                ScriptRegistrarBuilder scriptRegistrarBuilder = new ScriptRegistrarBuilder(scriptRegistrar);

 

                factory = new ViewComponentFactory<TModel>(helper, clientSideObjectWriterFactory, styleSheetRegistrarBuilder, scriptRegistrarBuilder);

 

                httpContext.Items[Key] = factory;

            }

            else

            {

                factory.HtmlHelper = helper;

            }

 

            return factory;

        }

 

        public static MvcHtmlString CustomStringTextBoxFor<TModel, TProperty>(

            this HtmlHelper<TModel> htmlHelper,

            Expression<Func<TModel, TProperty>> expression,

            object htmlAttributes

        )

        {

            var member = expression.Body as MemberExpression;

            var stringLength = member.Member

                .GetCustomAttributes(typeof(StringLengthAttribute), false)

                .FirstOrDefault() as StringLengthAttribute;

 

            var attributes = (IDictionary<string, object>)new RouteValueDictionary(htmlAttributes);

            if (stringLength != null)

            {

                attributes.Add("maxlength", stringLength.MaximumLength);

                attributes.Add("size", stringLength.MaximumLength);

            }

            return htmlHelper.TextBoxFor(expression, attributes);

        }

 

        public static MvcHtmlString CustomNumberTextBoxFor<TModel, TProperty>(

            this HtmlHelper<TModel> htmlHelper,

            Expression<Func<TModel, TProperty>> expression,

            object htmlAttributes

        )

        {

            var member = expression.Body as MemberExpression;

            var range = member.Member

                .GetCustomAttributes(typeof(RangeAttribute), false)

                .FirstOrDefault() as RangeAttribute;

 

            var attributes = (IDictionary<string, object>)new RouteValueDictionary(htmlAttributes);

            if (range != null)

            {

                attributes.Add("maxlength", range.Maximum.ToString().Length);

                attributes.Add("size", range.Maximum.ToString().Length);

            }

            return htmlHelper.TextBoxFor(expression, attributes);

        }

#endif

    }

}

 

Tags
TabStrip
Asked by
William Brown
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Eric
Top achievements
Rank 1
Chris Axe
Top achievements
Rank 1
Share this question
or