Currently, your treeview checkbox demo does not match the source code included on the page. The source code indicates there should be a "Find Checked Nodes" button, but your demo doesn't have this. When I do a View Source, I see that there is an onCheck script to report what has been checked.
In contrast, in my downloaded local demo source code (I am using MVC Q2 2014 SP2), the Find Checked Nodes button exists, but it doesn't do anything. I am brand new to MVC .NET and jQuery (with some experience with WebForms), so the inconsistencies make things even harder to understand.
What I WANT to happen is to get the checked values in my HTTPPost controller method, so I can do some database work with the results, but I can't figure out how to get the user checked values there. How can I do this?
My simplified model:
My simplified view:
My relevant controller methods:
In contrast, in my downloaded local demo source code (I am using MVC Q2 2014 SP2), the Find Checked Nodes button exists, but it doesn't do anything. I am brand new to MVC .NET and jQuery (with some experience with WebForms), so the inconsistencies make things even harder to understand.
What I WANT to happen is to get the checked values in my HTTPPost controller method, so I can do some database work with the results, but I can't figure out how to get the user checked values there. How can I do this?
My simplified model:
public
class
MyModel
{
public
string
OtherStuff {
get
;
set
;}
public
IEnumerable<TreeViewItemModel> treeData {
get
;
set
; }
}
My simplified view:
@model MyModel
<
text
>@Model.SomethingElse</
text
>
@(Html.Kendo().TreeView()
.Name("treeview-left")
.ExpandAll(true)
.Checkboxes(checkboxes => checkboxes
.Name("checkedPubIds")
.CheckChildren(true)
)
.BindTo(Model.treeData)
)
My relevant controller methods:
private
MyModel GetMyModel()
{
var model =
new
PubTreeModel
{
OtherStuff =
"Hello"
,
treeData = GetTreeData()
// implementation omitted here
};
return
model;
}
[HttpGet]
public
ActionResult Index()
{
var model = GetMyModel();
return
View(model);
}
[HttpPost]
public
ActionResult Index(MyModel model)
{
if
(ModelState.IsValid)
{
// Access Violation, because model.treeData is null. Why?
foreach
(var x
in
model.treeData)
{
if
(x.Checked)
{
// do something
}
}
}
// Have to do this or View(model) will break,
// because there is no treeData in it.
model = GetPubTreeModel(model.SelectedUserId);
return
View(model);
}