I have created one small demo with Tree View in MVC.
On Click of Node of a tree view details of the selected Note will show in Partial view.
In Current stage I have manage to achieve this.
but issue is that When I Click on 2nd page then Tree view is getting filled again which I don't want filled again and again.
I Just want to show tree view with selected values(old values).
Layout.cshtml
<html lang="en">
<head>
<title> Tree view Demo </title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/jqueryval1")
</head>
<body>
@*
*@
| @{
<script src="@Url.Content("~/Scripts/jquery.jstree.js")" type="text/javascript"></script>
<script type="text/javascript">
var divId = [];
var divText = [];
function GetIDs() {
divId = [];
divText = [];
$("#onflycheckboxes").jstree("get_checked", null, true).each
(function () {
divId.push(this.id);
divText.push($(this).children('a').text());
});
alert("Ids are:" + divId + " Text:" + divText);
}
function SubmitPlayers() {
var temp = "";
divId = [];
divText = [];
$("#onflycheckboxes").jstree("get_checked", null, true).each
(function () {
divId.push(this.id);
divText.push($(this).children('a').text());
temp = temp + this.id + ",";
});
$.ajax({
// Get Student PartialView
//url: "/Home/getPlayersData",
url: "/Home/TestView",
datatype: "Get",
data: { players: temp, Page_No: 1 },
success: function (data) {
$("#PlayersDetailTable").empty().append(data);
},
error: function () {
alert("something seems wrong");
}
});
}
</script>
<input id="btnSubmitPlayers" type="button" value="Submit1" onclick="SubmitPlayers();" />
<script type="text/javascript">
$(function () {
FillJSTree();
});
function FillJSTree() {
$("#onflycheckboxes").jstree({
json_data: {
"ajax": {
"url": "/Home/GetTreeData",
"type": "POST",
"dataType": "json",
"contentType": "application/json charset=utf-8"
}
},
checkbox: {
real_checkboxes: true,
checked_parent_open: true
},
plugins: ["themes", "json_data", "ui", "checkbox"]
});
}
</script>
}
|
@RenderBody()
</body>
</html>
TestView in Home Controller
public ActionResult TestView(string players, int? Page_No)
{
if (Session["Sessionplayers"] == null)
{
Session["Sessionplayers"] = players;
}
ViewBag.id = players;
HttpCookie hc = new HttpCookie("test", "1223");
Request.Cookies.Add(hc);
HttpCookie hc1 = new HttpCookie("courseName", Session["Sessionplayers"].ToString());
Request.Cookies.Add(hc1);
PlayerBusinessLayer playerBusinessLayer = new PlayerBusinessLayer();
List<SelectedPlayers> ObjselectedPlayers = playerBusinessLayer.GetAllPlayers(Session["Sessionplayers"].ToString()).ToList();
int Size_Of_Page = 4;
int No_Of_Page = (Page_No ?? 1);
ViewBag.PageCount = No_Of_Page;
//return PartialView("TestView", ObjselectedPlayers.ToPagedList(No_Of_Page,Size_Of_Page));
return View("TestView", ObjselectedPlayers.ToPagedList(No_Of_Page, Size_Of_Page));
}
TestView.cshtml
@*@model IEnumerable<businesslayer.selectedplayers>*@
@model PagedList.IPagedList<businesslayer.selectedplayers>
@using PagedList.Mvc;
@{
Layout = "~/Views/Shared/_LayoutNew.cshtml";
}
@foreach (var item in Model)
{
}
@Html.DisplayName("Select")
| Surname
| Initials
| BatSkill
| BowlPos
| FieldType
|
@Html.CheckBox("ABCD")
| @Html.DisplayFor(modelItem => item.Surname)
| @Html.DisplayFor(modelItem => item.Initials)
| @Html.DisplayFor(modelItem => item.BatSkill)
| @Html.DisplayFor(modelItem => item.BowlPos)
| @Html.DisplayFor(modelItem => item.FieldType)
|
<input type="button" value="Edit" />
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, Page_No => Url.Action("TestView", new { Page_No, Sorting_Order = ViewBag.CurrentSortOrder, Filter_Value = ViewBag.FilterValue }))