使用mvc4在jstree中显示xml数据时出错 [英] Error to show xml data in jstree with mvc4
问题描述
我在我的项目中添加了一个jstree(MVC 4)我从SQL(2012)获取数据并传递给Jstree中的show for cshtml但是不起作用。 (在警报显示数据中,但在jstree中不显示。):
public partial class gettree
{
public int CategoryID {get;组; }
public string Title {get;组; }
public string Comment {get;组; }
公共字符串XmlField {get;组; }
public Nullable < bool > 隐藏{get;组; }
public Nullable < bool > 已删除{get;组; }
public Nullable < int > 状态{get;组; }
public Nullable < int > TypeInfo {get;组; }
public Nullable < System.DateTime > CreateDate {get;组; }
public Nullable < System.DateTime > UpdateDate {get;组; }
public Nullable < int > OwnerID {get;组; }
public Nullable < int > AdminID {get;组; }
public Nullable < System.DateTime > ShowDate {get;组; }
public Nullable < int > OrderView {get;组; }
public Nullable < int > ParentID {get;组; }
public Nullable < int > CountVisite {get;组; }
public Nullable < int > CountChild {get;组; }
public Nullable < int > LanguageID {get;组; }
public Nullable < int > SiteID {get;组; }
public Nullable < int > 评分{get;组; }
公共字符串UniqueTitle {get;组; }
public Nullable < int > CID {get;组; }
public Nullable < int > PID {get;组; }
public int TotalRows {get;组; }
public int Sno {get;组; }
public string Edit {get;组; }
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(cat中的var项目)
{
if(item.ParentID == 0)
str + =< item id =' + item.CategoryID +' > < content > < 名称 > < 名称 > <![CDATA [ + item.Title +]]< / name>< / content> ;< /项目>中;
else str + =< item _parentid ='+ item.ParentID +'id ='+ item.CategoryID +'>< content>< name><![CDATA [ + item.Title + ]]> < < span class =code-leadattribute> / name > < / content > < / item > ;
}
str + =< / root < span class =code-keyword>> ;
return str;
}
}
我的cshtml:
@using(Html.BeginForm ())
{
@ Html.ValidationSummary(true)
}
< script type =text / javascript>
$(document).ready(function(){
Refresh ();
});
alert(('@ ViewData [Tree]'))
函数Refresh(){< br $>
$('#jstree')。jstree({
数据:{
类型:xml_nested ,
xml:@ Html.Raw(ViewData [Tree])
},themes:{
主题:默认,
dots:false,
icons:true,
url:〜/ Scripts / JSTree / dist / themes / default / style.css< br $>
},
});
}
< / script>
我的控制器:
public ActionResult 索引()
{
var s = new gettree();
var y = s.tr();
ViewData [ 树] = y;
return 查看();
}
这是我的剧本:
< span class =code-keyword>< 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 < span class =code-keyword> = 〜/ Scripts / modernizr-2.5.3.js > < / script >
< script src = 〜 /Theme/js/bootstrap.js\"> < / script >
< script src = 〜/ Scripts / jquery.validate.min.js > < span class =code-keyword>< / 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 >
(document).ready(function(){
Refresh();
});
alert(('@ ViewData [Tree]'))
函数Refresh(){
('#jstree')。jstree({
data:{
键入:xml_nested,
xml:@ Html.Raw(ViewData [Tree])
},themes:{
主题:默认,
点数:false,
图标:true,
url :〜/ Scripts / JSTree / dist / themes / default / style.css
},
});
}
< / script>
我的控制器:
public ActionResult 索引()
{
var s = new gettree();
var y = s.tr();
ViewData [ 树] = y;
return 查看();
}
这是我的剧本:
< span class =code-keyword>< 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 < span class =code-keyword> = 〜/ Scripts / modernizr-2.5.3.js > < / script >
< script src = 〜 /Theme/js/bootstrap.js\"> < / script >
< script src = 〜/ Scripts / jquery.validate.min.js > < span class =code-keyword>< / 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 >
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.) :
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 :
public ActionResult Index()
{
var s = new gettree();
var y = s.tr();
ViewData["Tree"] = y;
return View();
}
This is my scripts :
<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>
(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 :
public ActionResult Index() { var s = new gettree(); var y = s.tr(); ViewData["Tree"] = y; return View(); }
This is my scripts :
<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>
这篇关于使用mvc4在jstree中显示xml数据时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!