Good day. This must be a very basic thing to do, though I didn't manage to find any information on it.
I have a treeview setup like this:
@(
Html.Kendo().TreeView()
.Name("treeview")
.DataTextField("Text")
.DataSource(dataSource => dataSource.Read(read => read.Action("GetView", "Tree"))
)
My controller looks like this:
public
class
TreeController : Controller
{
private
readonly
IRepository _repository;
public
TreeController(IRepository repository)
{
_repository = repository;
}
[HttpGet]
public
JsonResult GetView()
{
var items = _repository.GetItems();
var viewmodel = items.Select(t =>
new
{
id = t.Id,
Text = t.Text,
hasChildren = t.HasChildren
});
return
Json(viewmodel, JsonRequestBehavior.AllowGet);
}
}
That part works just fine.
Now, I would like to add a button that would, say, rename the selected item. So,I know how to get the selected item in the treeview. What I do not know how to implement is the connection viewmodel -> data model. That is, knowing the selected html item I have no idea how to get the model item it coresponds to. That would be solvable if I could add my custom html "model-id" property on every item and pass it back to controller on my button click. Which I have no idea how to implement either.
Thank you in advance.