or
01.@model IEnumerable<KendoMVC.CostSimulatorService.Texto>02. 03.@{04. ViewBag.Title = "Textos";05. Layout = "~/Views/Shared/_Layout.cshtml";06.}07. 08.<h2>Textos</h2>09. 10.@(Html.Kendo().Grid(Model) // Bind the grid to the Model property of the view11. .Name("Grid")12. .Columns(columns =>13. {14. columns.Bound(p => p.Titulo); //Create a column bound to the "ProductID" property15. columns.Bound(p => p.IsPrivado)16. .ClientTemplate("<input type='checkbox' #= IsPrivado ? checked='checked': '' # class='chkbx' />")17. .Width(170); //Create a column bound to the "ProductName" property18. columns.ForeignKey(p => p.TipoTextoID, 19. (System.Collections.IEnumerable)ViewData["TiposTexto"], 20. "TipoTextoID", 21. "Designacao")22. .Title("Tipo de conteúdo").Width(170);23. columns.Command(command => 24. {25. command.Edit(); 26. command.Destroy().Text("Remover");27. }).Width(200).Title("Acções");28. })29. .ToolBar(commands => commands.Create())30. .Editable(editable => editable.Mode(GridEditMode.PopUp)31. .TemplateName("Texto")32. .Window(builder => builder33. .Width(800)34. .Height(570)35. .Modal(true)36. .Resizable(c => c.Enabled(true))37. .Animation(true)38. .Title("Editar conteúdo")))39. .DataSource(dataSource => dataSource40. .Ajax() //specify server type41. .PageSize(20)42. .Events(events => events.Error("error_handler"))43. .Model(model =>44. {45. model.Id(texto => texto.TextoID); // Specify the property which is the unique identifier of the model46. model.Field(texto => texto.TextoID).Editable(false); // Make the ProductID property not editable47. })48. .Create(create => create.Action("CreateTexto", "Textos"))49. .Read(read => read.Action("ReadTextos", "Textos"))50. .Update(update => update.Action("UpdateTexto", "Textos"))51. .Destroy(destroy => destroy.Action("DestroyTexto", "Textos")))52. .Pageable() // Enable paging53. .Sortable() // Enable sorting54. .Selectable()55. .Filterable()56. .Scrollable()57. )58. 59.<script type="text/javascript">60. 61. $(document).ready(function() { 62. $("form.k-edit-form").kendoValidator();63. });64. 65. function error_handler(e) {66. if (e.errors) {67. var message = "Errors:\n";68. $.each(e.errors, function (key, value) {69. if ('errors' in value) {70. $.each(value.errors, function () {71. message += this + "\n";72. });73. }74. });75. alert(message);76. }77. }78.</script>01.@using System.Web.Mvc.Html;02. 03.@model KendoMVC.CostSimulatorService.Texto04. 05.@Html.HiddenFor(model => model.TextoID)06.<div id="divWrapper" style="width:99%; float:left; height:520px; margin-left:2px;">07. <div>08. @Html.LabelFor(model => model.Titulo)09. </div>10. <div>11. @Html.TextBoxFor(model => model.Titulo, new { @class="k-textbox" , style = "width: 480px;" })12. @Html.ValidationMessageFor(model => model.Titulo)13. </div>14. <div>15. @Html.LabelFor(model => model.Corpo)16. </div>17. <div style="width:98%;">18. @(Html.Kendo().EditorFor(model => model.Corpo)19. .HtmlAttributes(new { style = "width: 740px;height:350px" })20. .ImageBrowser(imageBrowser => imageBrowser21. .Image("~/Content/Uploads/Images/{0}")22. .Read("Read", "Textos")23. .Create("Create", "Textos")24. .Destroy("Destroy", "Textos")25. .Upload("Upload", "Textos")26. .Thumbnail("Thumbnail", "Textos"))27. .Messages(m => m.DialogCancel("Cancelar")28. .DialogInsert("Inserir")29. .ImageAltText("Texto alternativo"))30. )31. @Html.ValidationMessageFor(model => model.Corpo)32. </div>33. <div>34. @Html.LabelFor(model => model.TipoTextoID)35. </div>36. <div>37. @Html.HiddenFor(model => model.TipoTextoID)38. @(Html.Kendo().DropDownListFor(model => model.TipoTextoID)39. .Name("TiposTexto")40. .DataTextField("Designacao")41. .DataValueField("TipoTextoID")42. .BindTo((System.Collections.IEnumerable) 43. ViewData["TiposTexto"]))44. </div>45. <div style="float:left; width:155px;">46. @Html.LabelFor(model => model.IsPrivado)47. </div>48. <div style="float:left;">49. @Html.CheckBoxFor(model => model.IsPrivado)50. @Html.ValidationMessageFor(model => model.IsPrivado)51. </div>52.</div>001.using System;002.using System.Data.Common.CommandTrees.ExpressionBuilder;003.using System.IO;004.using System.Linq;005.using System.Web;006.using System.Web.Mvc;007.using Kendo.Mvc.Extensions;008.using Kendo.Mvc.UI;009.using KendoMVC.CostSimulatorService;010.using KendoMVC.ImageBrowser.Models;011. 012.namespace KendoMVC.Controllers013.{014. public partial class TextosController : EditorImageBrowserController015. {016. #region Propriedades e Campos017. 018. private const string ContentFolderRoot = "~/Content/";019. private const string PrettyName = "Images/";020. private static readonly string[] foldersToCopy = new[] { "~/Content/Uploads/Shared/" };021. 022. #endregion023. 024. #region CRUD025. 026. #region ReadTextos027. 028. public ActionResult ReadTextos([DataSourceRequest]DataSourceRequest request)029. {030. CostSimulatorModel modelo = new CostSimulatorModel(new Uri(@"http://localhost:53212/CostSimulatorModelService.svc/"));031. 032. IQueryable<Texto> textos = modelo.Textos;033. DataSourceResult resultado = textos.ToDataSourceResult(request);034. ViewData["Textos"] = textos;035. return Json(resultado, JsonRequestBehavior.AllowGet);036. }037. 038. #endregion039. 040. #region CreateTexto041. 042. [ValidateInput(false)]043. public ActionResult CreateTexto([DataSourceRequest]DataSourceRequest request, Texto texto)044. {045. if (ModelState.IsValid)046. {047. CostSimulatorModel modelo = new CostSimulatorModel(new Uri(@"http://localhost:53212/CostSimulatorModelService.svc/"));048. 049. // Create a new Product entity and set its properties from the posted ProductViewModel050. Texto entity = new Texto051. {052. TextoID = texto.TextoID,053. Titulo = texto.Titulo,054. Corpo = texto.Corpo,055. IsPrivado = texto.IsPrivado,056. TipoTextoID = texto.TiposTexto != null ? texto.TiposTexto.TipoTextoID : texto.TipoTextoID,057. TiposTexto = texto.TiposTexto058. };059. modelo.AddToTextos(entity);060. // Insert the entity in the database061. modelo.SaveChanges();062. // Get the ProductID generated by the database063. texto.TextoID = entity.TextoID;064. return Json(new[] { entity }.ToDataSourceResult(request, ModelState));065. }066. // Return the inserted product. The grid needs the generated ProductID. Also return any validation errors.067. return Json(new[] { texto }.ToDataSourceResult(request, ModelState));068. }069. 070. #endregion071. 072. #region UpdateTexto073. 074. [ValidateInput(false)]075. public ActionResult UpdateTexto([DataSourceRequest]DataSourceRequest request, Texto texto)076. {077. if (ModelState.IsValid)078. {079. CostSimulatorModel modelo = new CostSimulatorModel(new Uri(@"http://localhost:53212/CostSimulatorModelService.svc/"));080. 081. // Create a new Product entity and set its properties from the posted ProductViewModel082. var entity = new Texto083. {084. TextoID = texto.TextoID,085. Titulo = texto.Titulo,086. Corpo = texto.Corpo,087. IsPrivado = texto.IsPrivado,088. TipoTextoID = texto.TiposTexto != null ? texto.TiposTexto.TipoTextoID : texto.TipoTextoID,089. TiposTexto = texto.TiposTexto090. };091. // Attach the entity092. modelo.AttachTo("Textos", entity);093. modelo.UpdateObject(entity);094. // Update the entity in the database095. modelo.SaveChanges();096. return Json(new[] { entity }.ToDataSourceResult(request, ModelState));097. }098. // Return the updated product. Also return any validation errors.099. return Json(new[] { texto }.ToDataSourceResult(request, ModelState));100. }101. 102. #endregion103. 104. #region DestroyTexto105. 106. public ActionResult DestroyTexto([DataSourceRequest]DataSourceRequest request, Texto texto)107. {108. if (ModelState.IsValid)109. {110. CostSimulatorModel modelo = new CostSimulatorModel(new Uri(@"http://localhost:53212/CostSimulatorModelService.svc/"));111. 112. // Create a new Product entity and set its properties from the posted ProductViewModel113. var entity = new Texto114. {115. TextoID = texto.TextoID116. };117. // Attach the entity118. modelo.AttachTo("Textos", entity);119. // Delete the entity120. modelo.DeleteObject(entity);121. 122. // Delete the entity in the database123. modelo.SaveChanges();124. return Json(new[] { entity }.ToDataSourceResult(request, ModelState));125. }126. // Return the removed product. Also return any validation errors.127. return Json(new[] { texto }.ToDataSourceResult(request, ModelState));128. }129. 130. #endregion131. 132. #endregion133. 134. #region ImageBrowser Code135. 136. /// <summary>137. /// Gets the base paths from which content will be served.138. /// </summary>139. public override string ContentPath140. {141. get142. {143. return CreateUserFolder();144. }145. }146. 147. private string CreateUserFolder()148. {149. var virtualPath = Path.Combine(ContentFolderRoot, "Uploads", PrettyName);150. 151. var path = Server.MapPath(virtualPath);152. if (!Directory.Exists(path))153. {154. Directory.CreateDirectory(path);155. foreach (var sourceFolder in foldersToCopy)156. {157. CopyFolder(Server.MapPath(sourceFolder), path);158. }159. }160. return virtualPath;161. }162. 163. private void CopyFolder(string source, string destination)164. {165. if (!Directory.Exists(destination))166. {167. Directory.CreateDirectory(destination);168. }169. 170. foreach (var file in Directory.EnumerateFiles(source))171. {172. var dest = Path.Combine(destination, Path.GetFileName(file));173. System.IO.File.Copy(file, dest);174. }175. 176. foreach (var folder in Directory.EnumerateDirectories(source))177. {178. var dest = Path.Combine(destination, Path.GetFileName(folder));179. CopyFolder(folder, dest);180. }181. }182. 183. #endregion184. }185.}Uncaught SyntaxError: Unexpected numberat.setter kendo.all.min.js:9lt.extend._set kendo.all.min.js:11Vt.extend.accept kendo.all.min.js:11lt.extend._accept kendo.all.min.js:11(anonymous function) kendo.all.min.js:11(anonymous function) jquery-1.10.2.js:3218fire jquery-1.10.2.js:3062self.fireWith jquery-1.10.2.js:3174deferred.(anonymous function) jquery-1.10.2.js:3263o.(anonymous function).call.X.success kendo.all.min.js:11fire jquery-1.10.2.js:3062self.fireWith jquery-1.10.2.js:3174done jquery-1.10.2.js:8249callback jquery-1.10.2.js:8792
public static IQueryable<TEntity> ApplyFiltering<TEntity>(this IQueryable<TEntity> queryable, IList<IFilterDescriptor> filters) where TEntity:class { foreach (var filter in filters.Cast<FilterDescriptor>()){ var pe = Expression.Parameter(typeof(TEntity), "x"); var left = Expression.Property(pe, typeof(TEntity).GetProperty(filter.Member)); queryable = queryable.Search(Expression.Lambda<Func<TEntity, object>>(left, new ParameterExpression[] { pe }), filter.Value.ToString()); } filters.Clear(); return queryable; }//And controller code: public ActionResult Data_Read([DataSourceRequest] DataSourceRequest request) { var query = repository.GetQueryable(); query = query.ApplyFilters(request.Filters); return Json(query.ToDataSourceResult(request)); }
@model CustomFieldsGroup@using (Html.BeginForm()){ @Html.HiddenFor(x => x.GroupID) @Html.HiddenFor(x => x.TypeID) <ul> <li> @Html.LabelFor(x => x.GroupName) </li> <li> @Html.EditorFor(x => x.GroupName) </li> </ul> <div class="edit-buttons"> <a class="k-button k-button-icontext k-update-button" href="\\#"><span class="k-icon k-update"></span>Save</a> <a class="k-button k-button-icontext k-cancel-button" href="\\#"><span class="k-icon k-cancel"></span>Cancel</a> </div>}<div class="k-toolbar k-grid-toolbar"> <a id="addRoleButton" class="k-button k-button-icontext k-add-button test" href="\\#"><span class="k-icon k-add"></span>Add new group</a></div><script type="text/x-kendo-tmpl" id="customFieldTemplate"> <div class="product-view k-widget"> <div class="edit-buttons"> <a class="k-button k-button-icontext k-edit-button" href="\\#"><span class="k-icon k-edit"></span></a> <a class="k-button k-button-icontext k-delete-button" href="\\#"><span class="k-icon k-delete"></span></a> </div> <div> Group Name </div> <div> ${GroupName} </div> @*<dl> <dt>GroupName</dt> <dd>${GroupName}</dd> <dt>Unit Price</dt> <dd>#:kendo.toString(UnitPrice, "c")#</dd> <dt>Units In Stock</dt> <dd>#:UnitsInStock#</dd> <dt>Discontinued</dt> <dd>#:Discontinued#</dd> </dl>*@ </div></script><div class="fields"> @(Html.Kendo().ListView<CustomFieldsGroup>(Model.Groups) .Name("listView") .ClientTemplateId("customFieldTemplate") .TagName("div") .DataSource(datasource => datasource.Model(model=> { model.Id(x => x.GroupID); model.Field(x => x.TypeID).Editable(false); model.Field(x => x.GroupName); }) .Read(ac => ac.Action("Index_Read", "CustomFields")) .Create(ac => ac.Action("CreateGroup", "CustomFields")) .Update(ac => ac.Action("EditGroup", "CustomFields"))) .Editable()) )</div><script> $(function () { var listView = $("#listView").data("kendoListView"); $(".test").bind("click", function (e) { listView.add(); e.preventDefault(); }) })</script>