Skip to content
Loading
}
if (stateregions.StateDetails.IsSelected != true)
{
  • @stateregions.StateDetails.Value
    @foreach (var region in stateregions.Regions)
    {
    if (region.IsSelected)
    {
  • @region.Value
  • }
    else
    {
  • @region.Value
  • }
    }
    }
    }
     
    do like this pass the models as like format hear i passed state region , region is related to states
     hope it will help u.
    just do it .
    i already implement this. so u start .if any issue come then ask me i will solve no problem
     
    Thnaks
     Brijesh 
    0
  • Abhilash J A
    0
    Hello Brijesh Rathor,
     
    Thank you... 'feeling inspiring' . I will try...
    0
  • Abhilash J A
    0
    Hello Brijesh,
     
    I have used jsTree. This is sql table. I have attached script file here. PFA. I have done this task by follow this url: http://techiesweb.net/2012/09/21/asp-net-mvc3-tree-view-with-jstree.html 
     
    But error occurred as shown below. 
     
     
     
     After I have added .edmx file. then the model class,
     
    1. public partial class Employee  
    2.     {  
    3.         public int ID { get; set; }  
    4.         public string Name { get; set; }  
    5.         public string SubName { get; set; }  
    6.         public Nullable<int> ManagerID { get; set; }  
    7.         public IList Employees { get; set; }  
    8.         public Employee()  
    9.         {  
    10.             Employees = new List();  
    11.         }  
    12.     }  
    1. public class GetDetails  
    2.    {  
    3.        public static List GetAllUsers()  
    4.        {  
    5.            DMSys_DBEntities db = new DMSys_DBEntities();  
    6.            return db.Employees.ToList();  
    7.        }  
    8.    }  
    Then I have created controller, 
    1. public ActionResult Index()  
    2.        {  
    3.            List userList = new List();  
    4.            userList = GetDetails.GetAllUsers();  
    5.            var president = userList.Where(x => x.ManagerID == 0).FirstOrDefault();  
    6.            SetChildren(president, userList);  
    7.            return View(president);  
    8.        }  
    9.   
    10.        private void SetChildren(Employee model, List userList)  
    11.        {  
    12.            var childs = userList.Where(x => x.ManagerID == model.ID).ToList();  
    13.            if (childs.Count > 0)  
    14.            {  
    15.                foreach (var child in childs)  
    16.                {  
    17.                    //SetChildren(childs, userList);  
    18.                    //model.Employees.Add(childs);  
    19.                    userList.Add(child);  
    20.                }  
    21.            }  
    22.        }  
     then, created view page
     
    1. @model MvcApplication6.Models.Employee  
    2. <script src="~/Scripts/jstree.js">script>  
    3. <link href="~/style.css" rel="stylesheet" />  
    4. <h2>Organization Treeh2>  
    5. <div id="divtree">  
    6.     <ul id="tree">  
    7.         <li>  
    8.             <a href="0" class="usr">  
    9.                 @Model.Name  
    10.             a>  
    11.             @Html.Partial("Children", Model)  
    12.         li>  
    13.     ul>  
    14. div>  
    15. <script type="text/javascript">  
    16.     $(function () {  
    17.         $('#divtree').jstree();  
    18.     })  
    19. script>  
    I have created Partial view, 
    1. @model MvcApplication6.Models.Employee  
    2. @{  
    3.     ViewBag.Title = "Children";  
    4. }  
    5. @foreach (var item in Model.Employees)  
    6. {  
    7.     <ul>  
    8.         @if (item != null)  
    9.         {  
    10.             <li>  
    11.                 <a href="0" class="usr">@item.Namea>  
    12.                 @if (item.Employees.Count > 0)  
    13.                 {  
    14.                     @Html.Partial("Children", item)   
    15.                 }  
    16.             li>   
    17.         }  
    18.     ul>   
    19. }  
     But, after run the application show this error.
     
     
     
    Please help me.
    0
  • Bikesh Srivastava
    0
    Please refer this link
    http://www.dotnetawesome.com/2014/06/how-to-create-treeview-with-database-data-mvc4-aspnet.html 
    0
  • Abhilash J A
    0
    Hello Bikesh,
     
    I have already tried that, but error occurred <a href="@i.NavURL">@i.MenuNamea> 
    where click on this. Because  my CompletePathName url is not look like this /Home/Index 
    0
  • 0
    HI Abhilash,
     
    I am some how not able to find attachement of code. I see the table script but the source code I could not locate.
     
    Can you please resend it?
     
    Thanks and regards,
    Chetan Ranpariya 
    0
  • Abhilash J A
    0
    Hello,
     
    Please find the attachment of treeview project. And the database table I have also attached by previous commend.
     
    Thanks 
    0
  • Abhilash J A
    0
    Thanks Chetan
    0