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

Object Reference not Set to Instance of an Object within Menu Animation

0 Answers 63 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 11 Apr 2011, 11:52 PM
Hi,

In working through the Menu Razor example, I created the following Menu in my solution:
@using Telerik.Web.Mvc.UI;
@{Html.Telerik().Menu()
.Name("NavMenu")
.Orientation(MenuOrientation.Horizontal)
.Effects(fx =>
            {
                if (ViewData["animation"].ToString() == "slide") { 
                    fx.Slide(); } 
                else if (ViewData["animation"].ToString() == "expand") { 
                    fx.Expand(); } 
                else { /* activate only toggle, so that the items show */                
                fx.Toggle(); } 
                if ((bool)ViewData["enableOpacityAnimation"]) 
                    fx.Opacity(); 
                fx.OpenDuration((int)ViewData["openDuration"])
                    .CloseDuration((int)ViewData["closeDuration"]);
            }
        )
.Items(menu =>
        {
            menu.Add()
                .Text("Home");
            menu.Add()
                .Text("About");
            menu.Add()
                .Text("Contact");
            menu.Add()
                .Text("Borrower")
                .Items(item =>
                    {
                        item.Add().Text("Sign Up");
                        item.Add().Text("Login");
                    });
            menu.Add()
                .Text("Investor")
                .Items(item =>
                    {
                        item.Add().Text("Sign Up");
                        item.Add().Text("Login");
                    });
            menu.Add()
                .Text("Dealer")
                .Items(item =>
                    {
                        item.Add().Text("Sign Up");
                        item.Add().Text("Login");
                    });
        })
.Render();
}

When I build and Publish the site, I receive the following error:
System.NullReferenceException: Object reference not set to an instance of an object at Line 7 which is the first ViewData If statement.  My HomeController is as follows:
public ActionResult MenuPartial()
        {
            return PartialView("MenuPartial");
        }
  
        public ActionResult AnimationEffects(
            string animation,
            bool? enableOpacityAnimation,
            int? openDuration,
            int? closeDuration)
        {
            ViewData["animation"] = animation ?? "slide";
            ViewData["animation"] = animation ?? "expand";
            ViewData["enableOpacityAnimation"] = enableOpacityAnimation ?? true;
            ViewData["openDuration"] = openDuration ?? 200;
            ViewData["closeDuration"] = closeDuration ?? 200;
            return View();
        }
    }

Can anyone suggest how to modify either the MenuPartial or HomeController to resolve the invalid object error?

Thanks,
Sid
Tags
Menu
Asked by
Sid
Top achievements
Rank 1
Share this question
or