Hii I am using jstree plugind and I want to create child nodes to a root node without refreshing page after adding root node But I am unable to do that.Please Help me...

$('button.create').click(function () {
            var parentid = null;
            var ref = $('#jstree').jstree(true),
            sel = ref.get_selected();
            if (sel.length) {
            sel = sel[0];
           console.log(sel)
            parentid = sel;

            }



            $("#jstree").jstree("create_node", parentid, null, "last", function (node) {
                this.edit(node);
                //$("#jstree").jstree("destroy");

            });


        });

and my controller code is

 public void AddEdit(ProductTypeMaster obj)
        {

            ProductTypesBO model = new ProductTypesBO();
            using (NilePlayEntities db = new NilePlayEntities())
            {
                if (obj.ID > 0)
                {

                    var old = db.ProductTypeMaster.Find(obj.ID);
                    old.ParentID = old.ParentID;
                    old.ProductType = obj.ProductType;
                    old.Position = obj.Position;
                    old.MenuLevel = obj.MenuLevel;
                    old.IsActive = old.IsActive;
                    old.CreatedAt = old.CreatedAt;
                    db.Entry(old).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();

                }

                else
                {

                    obj.CreatedAt = DateTime.Now;
                    obj.IsActive = true;
                    obj.MenuLevel = 1;

                    if (obj.ParentID == null)
                    {
                        obj.Position = 0;

                    }


                    db.ProductTypeMaster.Add(obj);
                    db.SaveChanges();
                }

                }


            }

I want to add child node after adding root node without refreshing page but I amunable to do that whenever I am trying to add child node to a new root node it is adding the child node as root node

0 Answers