using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace MCFD.MobilePolicy.MVC.Models{ public class SiteStructure { public SiteStructure() { } private List<string> next; private string myName = "N/A"; private List<InnerStructure> colHasChildren; private int ID; // Declare a Name property of type string: public string Name { get { return myName; } set { myName = value; } } public int id { get { return ID; } set { ID = value; } } //public bool HasChildren //{ // get // { // return hasChildren; // } // set // { // hasChildren = value; // } //} public List<InnerStructure> hasChildren { get { return colHasChildren; } set { colHasChildren = value; } } } public class InnerStructure { public InnerStructure() { } private List<string> next; private string myName = "N/A"; private List<InnerStructure> colHasChildren; private int ID; // Declare a Name property of type string: public string Name { get { return myName; } set { myName = value; } } public int id { get { return ID; } set { ID = value; } } //public bool HasChildren //{ // get // { // return hasChildren; // } // set // { // hasChildren = value; // } //} public List<InnerStructure> hasChildren { get { return colHasChildren; } set { colHasChildren = value; } } }}public JsonResult Employees(int? id) { //ulitimate goal is to transform this xml into a structure for the tree. I will deal with this later. Note that none of the bind to xml methods have worked for me. XElement xml = XElement.Load(Server.MapPath("~/App_Data/books.xml")); //Create 2 items for the tree Models.SiteStructure sitemapitem = new Models.SiteStructure(); sitemapitem.Name = "you"; sitemapitem.id = 1; Models.SiteStructure sitemapitem2 = new Models.SiteStructure(); sitemapitem2.Name = "me"; sitemapitem2.id = 2; //Create hierarchy by adding a new list to the first item in the root of items Models.InnerStructure sitemapitem3 = new Models.InnerStructure(); sitemapitem3.Name = "why does this not work?"; sitemapitem3.id = 3; List<Models.InnerStructure> sitemap2 = new List<Models.InnerStructure>(); sitemap2.Add(sitemapitem3); sitemapitem.hasChildren = sitemap2; //Add the items to list of items to return List<Models.SiteStructure> sitemap = new List<Models.SiteStructure>(); sitemap.Add(sitemapitem); sitemap.Add(sitemapitem2); return Json(sitemap, JsonRequestBehavior.AllowGet); }<div class="demo-section"> @(Html.Kendo().TreeView() .Name("treeview") .DataTextField("Name") .DataSource(dataSource => dataSource .Read(read => read .Action("Employees", "SiteEditor") ) ) ) </div>
@model IEnumerable<MyLibrary.Beamline>@{ ViewBag.Title = "Beamlines";}<h2>Beamlines</h2>@(Html.Kendo().Grid(Model) .Name("gvBeamlines") .Columns(columns => { columns.Command(command => { command.Edit(); }).Width(50); columns.Bound(o => o.Description).Width(100); columns.Bound(o => o.Insertion_Device).Title("Insertion Device"); columns.Bound(o => o.Status); columns.Bound(o => o.Energy_Range).Title("Energy Range"); columns.Command(command => { command.Destroy(); }).Width(50); }) .ToolBar(toolbar => toolbar.Create()) .Editable(editable => editable.Mode(GridEditMode.PopUp)) .Pageable() .Sortable() .DataSource(dataSource => dataSource .Server() .Model(model => model.Id(o => o.ID)) .Create(create => create.Action("Create", "Grid")) .Read(read => read.Action("Index", "Grid")) .Update(update => update.Action("Edit", "Grid")) .Destroy(destroy => destroy.Action("Delete", "Grid")) ) )using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using MyLibrary;namespace MyProject.Controllers{ public class BeamlinesController : Controller { // // GET: /Beamlines/ public ActionResult Index() { using (MyEntities context = new MyEntities()) { return View(context.Beamlines.ToList()); } } // // GET: /Beamlines/Details/5 public ActionResult Details(int id) { return View(); } // // GET: /Beamlines/Create public ActionResult Create() { return View(); } // // POST: /Beamlines/Create [HttpPost] public ActionResult Create(Beamline beamline) { try { // TODO: Add insert logic here return RedirectToAction("Index"); } catch { return View(); } } // // GET: /Beamlines/Edit/5 public ActionResult Edit(int id) { using (MyEntities context = new MyEntities()) { var beamline = context.Beamlines.Single(p => p.ID == id); return View(beamline); } } // // POST: /Beamlines/Edit/5 [HttpPost] public ActionResult Edit(int id, FormCollection collection) { using (MyEntities context = new MyEntities()) { var beamline = context.Beamlines.Single(p => p.ID == id); TryUpdateModel(beamline); if (ModelState.IsValid) { context.SaveChanges(); return RedirectToAction("Index"); } return View(beamline); } } // // GET: /Beamlines/Delete/5 public ActionResult Delete(int id) { return View(); } // // POST: /Beamlines/Delete/5 [HttpPost] public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here return RedirectToAction("Index"); } catch { return View(); } } }}
We are creating an MVC 4 application using the Kendo.Mvc helper assembly. The code is working well; however, we appear to be missing something when we try to obtain a reference to a kendo control.
Example:
Our application has an ActionLink on a toolbar. When the user clicks on the ActionLink, we call into a JS function to validate if the displayed grid has a row selected. Within the function we attempt to obtain a reference to the grid and get the selected row. Unfortunately, the select() function throws an error ("Value is undefined").
I have included the code below. Most of our logic will be based on controls having the ability to communicate with each other from events, etc. Are we able to receive the functionality using the MVC assembly, or are we only able to use the API when code in JS?
Any comments or assistance would be much appreciated.
Thanks,
Todd
@(Html.Kendo().Grid(Model.Transaction).Name("grid").Columns(columns => { columns.Bound(o => o.EntityId) .Hidden().Visible(false); columns.Bound(o => o.EntityName) .Sortable(true) .Title("Entity Name") .ClientTemplate(@Html.ActionLink("#=EntityName#", "Details", "Entity", new { id = "entityId" }, null).ToHtmlString().Replace("entityId", "#=EntityId#")); columns.Bound(o => o.TransactionType); columns.Bound(o => o.Name) .ClientTemplate(@Html.ActionLink("#=Name#", "Details", "Engagement", new { id = "engId" }, null).ToHtmlString().Replace("engId", "#=ID#")); columns.Bound(o => o.TransactionStatus); columns.Bound(o => o.Initiator); columns.Bound(o => o.Reason); }).Pageable(p => p.PageSizes(true)).Filterable(filterable => filterable .Extra(false) .Operators(operators => operators .ForString(str => str.Clear() .StartsWith("Starts with") .IsEqualTo("Is equal to") .IsNotEqualTo("Is not equal to") )) ) .Navigatable().Resizable(resize => resize.Columns(true)).Selectable().DataSource(dataSource => dataSource .Ajax() .Model(model => model.Id(p => p.ID)) .Read(r => r.Action("Search", "Transaction"))))getSelectedRowId: function (gridId) { var grid = jQuery(gridId).kendoGrid().data("kendoGrid"); var row = grid.select(); if (row.length > 0) return grid.dataItem(row).id; else return null; }
I tried this on http://jsfiddle.net/rusev/E3vYH/ and it works fine. Now I have a listView generated by ListView Kendo Helper and I add a model by calling DataSource.add() method, but when I call DataSource.sync() it doesn't call create and I don't see any http activity on my browser's network tab. I copied the code generated by the kendo helper and pasted it into a test html file and it doesn't work neither. It did add the model to the listView but never calls create. Here is my test file:
<!DOCTYPE html>
<html>
<head>
<title>Testing Kendoui dataSource</title>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
<script src="http://cdn.kendostatic.com/2012.2.710/js/kendo.all.min.js"></script>
<script type="text/x-kendo-tmpl" id="template">
<div data-id = ${CountryCode}>
<p>${CountryName}</p>
</div >
</script>
<script>
$(function () {
$("#target").kendoListView ({
"dataSource": {
"transport": {
"prefix": "",
"read": function () {
alert("reading...");
},
"create": function () {
alert("creating...");
},
"destroy": function () {
alert("destroying...");
},
"update": function () {
alert("updating...");
}
},
"type": "aspnetmvc-ajax",
"schema": {
"data": "Data",
"total": "Total",
"errors": "Errors",
"model": {
"id": "SubaccountId",
"fields": {
"SubaccountId": {
"type": "number"
},
"CountryCode": {
"type": "string"
},
"CountryName": {
"type": "string"
}
}
}
}
},
"template": kendo.template($('#template').html()),
"selectable": "single"
});
$('#addButton').bind("click", function () {
var ds = $('#target').data('kendoListView').dataSource;
ds.add({
SubaccountId: 1,
CountryCode: 'US',
CountryName: 'United States'
});
ds.sync();
});
});
</script>
</head>
<body>
<div>
<button id="addButton">Add Country</button>
</div>
<div id="target"></div>
</body>
</html>
I tried with different jquery and kendo version too. No luck.
How do I make this work.
Thanks
D
@(Html.Kendo().NumericTextBoxFor(m => m.FilterParticipants).Format("n0").Min(1).Decimals(0))[Required(ErrorMessageResourceName = "ValidationRequired", ErrorMessageResourceType = typeof(Resources.Global))]
//[Min(1, ErrorMessageResourceName = "ValidationRequired", ErrorMessageResourceType = typeof(Resources.Global))]
public int FilterParticipants { get; set; }columns.Bound(i => i.WeightUOM) .EditorTemplateName("ItemGrid_RefUOMListingWeight") .Width(50);columns.Bound(i => i.NMFC).Width(50); var itemGrid = $("#QuoteItemGrid").data("kendoGrid");itemGrid.hideColumn("NMFC");