Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I add a jstree in my project(MVC 4) i get data from SQL(2012) and pass to the cshtml for show in Jstree but dont work . (In alert show data but in jstree dont show.) :
XML
public partial class gettree
   {
       public int CategoryID { get; set; }
       public string Title { get; set; }
       public string Comment { get; set; }
       public string XmlField { get; set; }
       public Nullable<bool> Hidden { get; set; }
       public Nullable<bool> Deleted { get; set; }
       public Nullable<int> Status { get; set; }
       public Nullable<int> TypeInfo { get; set; }
       public Nullable<System.DateTime> CreateDate { get; set; }
       public Nullable<System.DateTime> UpdateDate { get; set; }
       public Nullable<int> OwnerID { get; set; }
       public Nullable<int> AdminID { get; set; }
       public Nullable<System.DateTime> ShowDate { get; set; }
       public Nullable<int> OrderView { get; set; }
       public Nullable<int> ParentID { get; set; }
       public Nullable<int> CountVisite { get; set; }
       public Nullable<int> CountChild { get; set; }
       public Nullable<int> LanguageID { get; set; }
       public Nullable<int> SiteID { get; set; }
       public Nullable<int> Rating { get; set; }
       public string UniqueTitle { get; set; }
       public Nullable<int> CID { get; set; }
       public Nullable<int> PID { get; set; }
       public int TotalRows { get; set; }
       public int Sno { get; set; }
       public string Edit { get; set; }
       public string tr()
       {
           var ctdb = new WebSite_CategoryDB();
           MPortalExampleContext db = new MPortalExampleContext();
           var cat = db.WebSite_CategoryDB.Where(x => x.LanguageID == 0
               && x.TypeInfo == 0 && x.SiteID == 0).ToList();

           var str = "<root>";
           foreach (var item in cat)
           {
               if (item.ParentID == 0)
                   str += "<item id='" + item.CategoryID + "'><content><name><name><![CDATA[" + item.Title + "]]</name></content></item>";
               else str += "<item _parentid='" + item.ParentID + "' id='" + item.CategoryID + "'><content><name><![CDATA[" + item.Title + "]]></name></content></item>";

           }
           str += "</root>";
           return str;
       }
   }


My cshtml :
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)





}
<script type="text/javascript">
$(document).ready(function () {
Refresh();
});
alert(('@ViewData["Tree"]'))
function Refresh() {

$('#jstree').jstree({
data: {
type: "xml_nested",
xml: "@Html.Raw(ViewData["Tree"])"
},"themes": {
"theme": "default",
"dots": false,
"icons": true,
"url": "~/Scripts/JSTree/dist/themes/default/style.css"
},

});
}

</script>
My controller :
SQL
public ActionResult Index()
       {
           var s = new gettree();
           var y = s.tr();
           ViewData["Tree"] = y;
           return View();
       }


This is my scripts :
XML
<link href="~/Scripts/JSTree/dist/themes/default/style.css" rel="stylesheet" />
   <link href="~/Content/Site.css" rel="stylesheet" />
   <script src="~/Scripts/jquery-1.7.1.min.js"></script>
   <script src="~/Scripts/modernizr-2.5.3.js"></script>
   <script src="~/Theme/js/bootstrap.js"></script>
   <script src="~/Scripts/jquery.validate.min.js"></script>
   <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
   <script src="~/Scripts/ckeditor/ckeditor.js"></script>
   <script src="~/Scripts/JSTree/dist/libs/jquery.js"></script>
   <script src="~/Scripts/JSTree/dist/jstree.min.js"></script>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900