Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7923483

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:20:29+00:00 2026-06-03T17:20:29+00:00

I try to create Data Driven Menu in MVC 3. So i complete following

  • 0

I try to create Data Driven Menu in MVC 3. So i complete following code :

Model :

#region MenuTree
    public class MenuTree : BusinessObject
    {

        #region  Constructor
        public MenuTree()
        {

        }
        #endregion

        #region Property
        #region ParentID
        private int _nParentID;
        public int ParentID
        {
            get { return _nParentID; }
            set { _nParentID = value; }
        }
        #endregion
        #region MenuName
        private string _sMenuName;
        public string MenuName
        {
            get { return _sMenuName; }
            set { _sMenuName = value; }
        }
        #endregion
        #region LinkText
        private string _sLinkText;
        public string LinkText
        {
            get { return _sLinkText; }
            set { _sLinkText = value; }
        }
        #endregion
        #region ActionName
        private string _sActionName;
        public string ActionName
        {
            get { return _sActionName; }
            set { _sActionName = value; }
        }
        #endregion
        #region ControllerName
        private string _sControllerName;
        public string ControllerName
        {
            get { return _sControllerName; }
            set { _sControllerName = value; }
        }
        #endregion
        #endregion

        #region Functions
        public MenuTree Get(int MenuTreeID)
        {
            return MenuTreeService.Instance.Get(new ID(MenuTreeID));
        }

        public ID Save()
        {
            return MenuTreeService.Instance.Save(this);
        }
        public void Delete()
        {
            MenuTreeService.Instance.Delete(ID);
        }
        #endregion
    }  

Controller Part :

    public class TreeMenuController : Controller
        {
            //
            // GET: /TreeMenu/

            public ActionResult Index()
            {
                return View(MenuTrees.Gets());
            }

        }



view : 



@model ESimSolMVC05.Models.MenuTrees
@{
    ViewBag.Title = "Index";
}


<table>
    <thead> 
    <tr>
        <th> ID </th>
        <th> ParentID</th>
        <th> Menu Name</th>      
    </tr>
    </thead>
    <tbody>

    @foreach (ESimSolMVC05.Models.MenuTree item in Model)
    {
    <tr>
        <td>@Html.DisplayFor(modelItem => item.ObjectID)</td>
        <td>@Html.DisplayFor(modelItem => item.ParentID)</td>
        <td>@Html.DisplayFor(modelItem => item.MenuName)</td>       
    </tr>

    }
</tbody>
</table>

then I try to call my view as a partial view in _layout with following code :

@Html.Partial("~/Views/TreeMenu/index.cshtml")

But When i run my project I get an exception

My Exception Message is : Object reference not set to an instance of an object.

Any one suggest me I can I call a partial view

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T17:20:31+00:00Added an answer on June 3, 2026 at 5:20 pm
    public PartialViewResult Index()
    {
         return PartialView(MenuTrees.Gets());
    }
    

    use:

    @Html.Partial("Index","TreeMenu")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to create a multi-threaded singleton pattern class. Header: class HL{ public: static
I try to create a form that can save a person's form data so
I have the following entities in Entity Framework: public class School { public int
I am getting following error when I try to open MySQL Connection; MySql.Data.MySqlClient.MySqlException: Unable
I created an iPhone project using the Core Data template. Now when I try
I want to try create something like Zend's Server Pagecache. What I want to
I try to create a new file inside a JSP and try to save
I try to create a thread in QT, can declare, create and start it,
I try to create a very simple app using windows API. I've done some
I try to create 2 buttons inside my app case WM_CREATE:{ hWnd =CreateWindowEx(NULL, LBUTTON,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.