Hi,
I'm currently testing the kendo MVC Grid with Ajax Binding, and i have a getPedidosByColabId function in my repository, and a controller with GetListaGrid function that returns data to populate the grid and i'm getting this error "Public member 'ToDataSourceResult' on type 'ObjectQuery(Of PedidoDocumentacaoViewModel)' not found.". Any Help?
Public Function getPedidosByColabId(ByVal idColaborador As Integer) Dim listaPedidos = (From l In db.tblPEDDOC__tblPedidoDocumentacao Where l.idColaborador = idColaborador Select New PedidoDocumentacaoViewModel With { .idPedidoDocumentacao = l.idPedidoDocumentacao, .idEstadoPedidoDoc = l.idEstadoPedidoDoc, .descEstadoPedidoDoc = l.tblPEDDOC__tblEstadoPedidoDoc.descEstadoPedidoDoc, .idTipoPedidoDoc = l.idTipoPedidoDoc, .descTipoPedidoDoc = l.tblPEDDOC__tblTipoPedidoDoc.descTipoPedidoDoc, .data = l.data }) Return listaPedidos End Function
Public Function GetListaGrid(<DataSourceRequest()> request As DataSourceRequest) As ActionResult Dim idColaborador As Integer = 979 Dim pRepository As New PedidosRepository Dim res = pRepository.getPedidosByColabId(idColaborador) Dim result As DataSourceResult = res.ToDataSourceResult(request) Return Json(result) End Function
Dim result As DataSourceResult = New DataSourceResult With {.Data = res}
Sorry for the trouble
Hi,
With this viewcode I am trying to create a grid hierachy to be editable. The first level grid works , but the 2.nd level does not Update when creating/editing, I get this ModelState error when runnig ReviewCategory_Update , " The parameter conversion from type 'System.String' to type 'Reviews.Models.ReviewCategory' failed because no type converter can convert between these types. " , 'Reviews.Models.ReviewCategory' is the class used to populate the 2.nd level grid.
<ul data-role="listview" data-inset="true"> <li data-role="list-divider">Navigation</li> <li>@Html.ActionLink("About", "About", "Home")</li> <li>@Html.ActionLink("Contact", "Contact", "Home")</li></ul>@(Html.Kendo().Grid<Reviews.Models.Review>().Name("ReviewGrid").Columns(columns =>{ columns.Bound(p => p.Customer); columns.Bound(p => p.Location); columns.Bound(p => p.Title); columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200); }).ToolBar(toolbar=>toolbar.Create()) .DetailTemplate(detail=>detail.ClientTemplate( Html.Kendo().Grid<Reviews.Models.ReviewCategory>() .Name("ReviewCategory_#=ReviewId#") .Columns(columns=> { columns.Bound(o => o.TableNo); columns.Bound(o => o.Category); columns.Bound(o => o.Comment); columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200); }) .ToolBar(toolbar => toolbar.Create()) .Editable(editable => editable.Mode(GridEditMode.InLine)) .Pageable() .Sortable() .Scrollable() .DataSource(dataSource => dataSource .Ajax() .Events(events => { events.Error("error_handler"); }) .Model(model => model.Id(p => p.Id)) .Create(update => update.Action("ReviewCategory_Create", "Home", new { id = "#=ReviewId#" })) .Read(read => read.Action("ReviewCategory_Read", "Home", new { id = "#=ReviewId#" })) .Update(update => update.Action("ReviewCategory_Update", "Home")) .Destroy(update => update.Action("ReviewCategory_Destroy", "Home")) ) .ToHtmlString() )).Editable(editable=>editable.Mode(GridEditMode.InLine)) .Pageable() .Sortable() .Scrollable() .DataSource(dataSource => dataSource .Ajax() .Events(events => { events.Error("error_handler"); }) .Model(model=>model.Id(p=>p.ReviewId)) .Create(update=>update.Action("Review_Create","Home")) .Read(read => read.Action("Review_Read", "Home")) .Update(update => update.Action("Review_Update", "Home")) .Destroy(update => update.Action("Review_Destroy", "Home")) ))<script type="text/javascript"> function error_handler(e) { if (e.errors) { var message = "Errors:\n"; $.each(e.errors, function (key, value) { if ('errors' in value) { $.each(value.errors, function () { message += this + "\n"; }); } }); alert(message); } } function dataBound() { this.expandRow(this.tbody.find("tr.k-master-row").first()); }</script> using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using Kendo.Mvc.UI;using Kendo.Mvc.Extensions;using Reviews.Models;using System.Data.Metadata.Edm;using System.Data.Objects.DataClasses;namespace Reviews.Controllers{ public class HomeController : Controller { ReviewModelContainer reviewContext = new ReviewModelContainer(); public ActionResult Index() { ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; return View(); } public ActionResult Review_Read([DataSourceRequest] DataSourceRequest request) { //return Json(SessionProductRepository.All().ToDataSourceResult(request)); return Json(reviewContext.ReviewSet.ToDataSourceResult(request)); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult Review_Create([DataSourceRequest] DataSourceRequest request, Review review) { if (review != null && ModelState.IsValid) { reviewContext.AddToReviewSet(review); reviewContext.SaveChanges(); } return Json(new[] { review }.ToDataSourceResult(request, ModelState)); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult EditingInline_Update([DataSourceRequest] DataSourceRequest request, Review review) { if (review != null && ModelState.IsValid) { int currentid = review.ReviewId; Review target = reviewContext.ReviewSet.Where(p => p.ReviewId == currentid).First(); if (target != null) { target.Customer = review.Customer; target.Location = review.Location; target.Title = review.Title; reviewContext.SaveChanges(); } } return Json(ModelState.ToDataSourceResult()); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult EditingInline_Destroy([DataSourceRequest] DataSourceRequest request, Review review) { if (review != null) { reviewContext.DeleteObject(review); reviewContext.SaveChanges(); } return Json(ModelState.ToDataSourceResult()); } public ActionResult ReviewCategory_Read(int id, [DataSourceRequest] DataSourceRequest request) { EntityCollection<Models.ReviewCategory> categories = reviewContext.ReviewSet.Where(Review => Review.ReviewId == id).First().ReviewCategory; return Json(categories.ToDataSourceResult(request)); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult ReviewCategory_Create(int id, [DataSourceRequest] DataSourceRequest request, ReviewCategory category) { if (category != null && ModelState.IsValid) { category.Review = reviewContext.ReviewSet.Where(t => t.ReviewId == id).First(); reviewContext.AddToReviewCategorySet(category); reviewContext.SaveChanges(); } return Json(new[] { category }.ToDataSourceResult(request, ModelState)); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult ReviewCategory_Update([DataSourceRequest] DataSourceRequest request, ReviewCategory category) { if (category != null && ModelState.IsValid) { int currentid = category.Id; ReviewCategory target = reviewContext.ReviewCategorySet.Where(p => p.Id == currentid).First(); if (target != null) { target.TableNo = category.TableNo; target.Category = category.Category; target.Comment = category.Comment; reviewContext.SaveChanges(); } } return Json(ModelState.ToDataSourceResult()); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult ReviewCategory_Destroy([DataSourceRequest] DataSourceRequest request, ReviewCategory category) { if (category != null) { reviewContext.DeleteObject(category); reviewContext.SaveChanges(); } return Json(ModelState.ToDataSourceResult()); } public ActionResult About() { ViewBag.Message = "Your quintessential app description page."; return View(); } public ActionResult Contact() { ViewBag.Message = "Your quintessential contact page."; return View(); } }}public class InCartProduct { public string ProductId { get; set; } public string Fabric { get; set; } public string Pattern { get; set; } public string Color { get; set; } public string Description { get; set; } public double Qty { get; set; } public double UPrice { get; set; } public double Total { get; set; } }@model IEnumerable<pts.Models.InCartProduct>@{ ViewBag.Title = "Shopping Cart";}<h2>Your Order</h2><h3>Fabrics</h3>@(Html.Kendo().Grid(Model) .Name("FabricGrid") .Columns(columns => { columns.Bound(p => p.Pattern).Groupable(false); columns.Bound(p => p.Description); columns.Bound(p => p.UPrice); columns.Bound(p => p.Qty).Width(150); columns.Bound(p => p.Total).ClientFooterTemplate("Order Total : "); columns.Command(command => command.Destroy()).Width(110); }) .ToolBar(commands => { commands.Save().SaveText("Update Fabric Order"); }) .Scrollable() .Sortable() .Editable(editable => editable.Mode(GridEditMode.InCell)) .DataSource(dataSource => dataSource .Ajax() .Batch(true) .ServerOperation(false) .Model(model => model.Id(p => p.ProductId)) .Events(events => events.Error("error_handler")) .Create(create => create.Action("Product_Create ", "ShoppingCart")) .Read(read => read.Action("Product_Read", "ShoppingCart")) .Update(update => update.Action("Product_Update", "ShoppingCart")) .Destroy(update => update.Action("Product_Delete", "ShoppingCart")) ))[AcceptVerbs(HttpVerbs.Post)]public ActionResult Product_Update([DataSourceRequest] DataSourceRequest request, InCartProduct product){ if (product != null) { // do something } return Json(ModelState.ToDataSourceResult());}Invalid JSON primitive: sort." error (see attached). The error occurs before it hits the controller. A break point in the controller never gets hit. If I remove all the paramters from the controller i.e.: public ActionResult Product_Update() the program does hit the break point in the controller but it's pretty useless at this point.<script language="javascript" type="text/javascript"> jQuery.support.cors = true; $.ajaxSetup({ type: 'POST', contentType: "application/json; charset=utf-8", dataType: "json", data: "{}", success: function (msg) { console.log(msg.d); }, error: function (xhr, desc, ex) { alert("Web Service Error: " + xhr.responseText + ", " + desc + ": " + ex); } }); function namespace(namespaceString) { var parts = namespaceString.split('.'), parent = window, currentPart = ''; for (var i = 0, length = parts.length; i < length; i++) { currentPart = parts[i]; parent[currentPart] = parent[currentPart] || {}; parent = parent[currentPart]; } return parent; } var myajax = namespace('myajax'); myajax.WebService = { Url: 'ptsGenericService.asmx/', _Ajax: function (url, callback) { $.ajax({ url: url, success: callback }); }, GetMenu: function (callback) { var url = this.Url + 'GetMenu'; this._Ajax(url, callback); } }; $(document).ready(function () { myajax.WebService.GetMenu(function (menulist) { var menu = $("#menu").kendoMenu().data("kendoMenu"); var parentItem = null; $(menulist.d).each(function (rec) { var parentItem = menu.element.children("li:contains('" + this.ParentTitle + "')"); if (this.ParentTitle == '' || parentItem.length == 0) { menu.append({ text: this.Title, url: this.Link, imageUrl: this.IconUrl, spriteCssClass: this.SpriteCssClass }); } else { if (this.SubTitle == null || this.SubTitle == '') { menu.append([{ text: this.Title, url: this.Link, imageUrl: this.IconUrl, spriteCssClass: this.SpriteCssClass}], parentItem); } else { if (this.SubTitle != "") { var subItem = parentItem.find("li:contains('" + this.Title + "')"); menu.append([{ text: this.SubTitle, url: this.Link, imageUrl: this.IconUrl, spriteCssClass: this.SpriteCssClass}], subItem); } } } }); }); }); </script>After receiving your email about the future of the MVC Extensions, I have begun to look into what the cost(engineering time) to convert our MVC Extension UI's to KendoUI.
We would like to use the new server side scripting you have added with the latest beta. We are currently in the beginning stages of our project but have already used a bunch of MVC Extensions heavily.
The first problem I am seeing is getting the TabStrip to fill up the whole window (except for the header) and have a splitter control fill up a particular tab. I had some issues getting this to work before but was able to resolve them using the MVC forums.
The Tabstrip is ajax loaded and is pretty simple. I have included an example of our application with a stripped down set of controls that just show the basic functionality.
I appreciate the help and hope to hear from you soon.
Thanks,
Lucas