Skip to content

Commit 4251fcf

Browse files
committed
chore(examples): update EF version and add grid editing examples
1 parent cb52431 commit 4251fcf

File tree

124 files changed

+11180
-346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+11180
-346
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using Kendo.Mvc.Extensions;
2+
using Kendo.Mvc.UI;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Web;
8+
using System.Web.Mvc;
9+
using Telerik.Examples.Mvc.Areas.GridAjaxBindingCustomJsonResult.Models;
10+
using Telerik.Examples.Mvc.Areas.GridAjaxBindingCustomJsonResult.Serialization;
11+
12+
namespace Telerik.Examples.Mvc.Areas.GridAjaxBindingCustomJsonResult.Controllers
13+
{
14+
public class HomeController : Controller
15+
{
16+
private static List<Product> products = new List<Product>();
17+
private static int id;
18+
19+
static HomeController()
20+
{
21+
// create some large data
22+
for (id = 1; id < 100000; id++)
23+
{
24+
products.Add(new Product()
25+
{
26+
ID = id,
27+
Name = "Product" + id
28+
});
29+
}
30+
}
31+
32+
// GET: GridAjaxBindingCustomJsonResult/Home
33+
public ActionResult Index()
34+
{
35+
return View();
36+
}
37+
38+
protected override JsonResult Json(object data, string contentType,
39+
Encoding contentEncoding, JsonRequestBehavior behavior)
40+
{
41+
return new CustomJsonResult
42+
{
43+
Data = data,
44+
ContentType = contentType,
45+
ContentEncoding = contentEncoding,
46+
JsonRequestBehavior = behavior
47+
};
48+
}
49+
50+
public ActionResult Read([DataSourceRequest] DataSourceRequest request)
51+
{
52+
return Json(products.ToDataSourceResult(request));
53+
}
54+
55+
public ActionResult LocalData()
56+
{
57+
return View(products);
58+
}
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Web.Mvc;
2+
3+
namespace Telerik.Examples.Mvc.Areas.GridAjaxBindingCustomJsonResult
4+
{
5+
public class GridAjaxBindingCustomJsonResultAreaRegistration : AreaRegistration
6+
{
7+
public override string AreaName
8+
{
9+
get
10+
{
11+
return "GridAjaxBindingCustomJsonResult";
12+
}
13+
}
14+
15+
public override void RegisterArea(AreaRegistrationContext context)
16+
{
17+
context.MapRoute(
18+
"GridAjaxBindingCustomJsonResult_default",
19+
"GridAjaxBindingCustomJsonResult/{controller}/{action}/{id}",
20+
new { action = "Index", id = UrlParameter.Optional }
21+
);
22+
}
23+
}
24+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
6+
namespace Telerik.Examples.Mvc.Areas.GridAjaxBindingCustomJsonResult.Models
7+
{
8+
public class Product
9+
{
10+
public int ID { get; set; }
11+
public string Name { get; set; }
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Kendo.Mvc.Infrastructure;
2+
using Newtonsoft.Json;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Web;
7+
8+
namespace Telerik.Examples.Mvc.Areas.GridAjaxBindingCustomJsonResult.Serialization
9+
{
10+
public class CustomJavaScriptSerializer : IJavaScriptSerializer
11+
{
12+
public string Serialize(object value)
13+
{
14+
return JsonConvert.SerializeObject(value);
15+
}
16+
}
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Kendo.Mvc.Infrastructure;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Web;
6+
7+
namespace Telerik.Examples.Mvc.Areas.GridAjaxBindingCustomJsonResult.Serialization
8+
{
9+
public class CustomJsonInitializer : JavaScriptInitializer
10+
{
11+
public override IJavaScriptSerializer CreateSerializer()
12+
{
13+
return new CustomJavaScriptSerializer();
14+
}
15+
}
16+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Net.Mime;
6+
using System.Web;
7+
using System.Web.Mvc;
8+
using Telerik.SvgIcons;
9+
10+
namespace Telerik.Examples.Mvc.Areas.GridAjaxBindingCustomJsonResult.Serialization
11+
{
12+
public class CustomJsonResult : JsonResult
13+
{
14+
const string JsonRequest_GetNotAllowed = "This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.";
15+
16+
public JsonSerializerSettings Settings { get; private set; }
17+
18+
public override void ExecuteResult(ControllerContext context)
19+
{
20+
if (context == null)
21+
{
22+
throw new ArgumentNullException("context");
23+
}
24+
25+
if ((JsonRequestBehavior == JsonRequestBehavior.DenyGet) && string.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
26+
{
27+
throw new InvalidOperationException(JsonRequest_GetNotAllowed);
28+
}
29+
30+
var response = context.HttpContext.Response;
31+
if (!string.IsNullOrEmpty(ContentType))
32+
{
33+
response.ContentType = ContentType;
34+
}
35+
else
36+
{
37+
response.ContentType = "application/json";
38+
}
39+
40+
if (ContentEncoding != null)
41+
{
42+
response.ContentEncoding = ContentEncoding;
43+
}
44+
45+
if (Data != null)
46+
{
47+
response.Write(JsonConvert.SerializeObject(this.Data));
48+
}
49+
}
50+
}
51+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@using Kendo.Mvc.UI
2+
3+
@{
4+
ViewBag.Title = "Index";
5+
}
6+
7+
<h2>Index</h2>
8+
9+
@(Html.Kendo().Grid<Telerik.Examples.Mvc.Areas.GridAjaxBindingCustomJsonResult.Models.Product>()
10+
.Name("Grid")
11+
.Columns(columns =>
12+
{
13+
columns.Bound(p => p.ID);
14+
columns.Bound(p => p.Name);
15+
})
16+
.Pageable()
17+
.Sortable()
18+
.Filterable()
19+
.DataSource(dataSource => dataSource
20+
.Ajax()
21+
.ServerOperation(false)
22+
.Read("Read", "Home")
23+
)
24+
)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@using Kendo.Mvc.UI
2+
3+
@{
4+
ViewBag.Title = "Local data";
5+
}
6+
7+
@model IEnumerable<Telerik.Examples.Mvc.Areas.GridAjaxBindingCustomJsonResult.Models.Product>
8+
9+
<h2>Bound to local data</h2>
10+
11+
@(Html.Kendo().Grid(Model)
12+
.Name("Grid")
13+
.Columns(columns =>
14+
{
15+
columns.Bound(p => p.ID);
16+
columns.Bound(p => p.Name);
17+
})
18+
.Pageable()
19+
.Sortable()
20+
.Filterable()
21+
.DataSource(dataSource => dataSource
22+
.Ajax()
23+
.ServerOperation(false)
24+
)
25+
)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>@ViewBag.Title - My ASP.NET Application</title>
7+
@Styles.Render("~/Content/css")
8+
@Scripts.Render("~/bundles/modernizr")
9+
</head>
10+
<body>
11+
<div class="navbar navbar-inverse navbar-fixed-top">
12+
<div class="container">
13+
<div class="navbar-header">
14+
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
15+
<span class="icon-bar"></span>
16+
<span class="icon-bar"></span>
17+
<span class="icon-bar"></span>
18+
</button>
19+
@Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
20+
</div>
21+
<div class="navbar-collapse collapse">
22+
<ul class="nav navbar-nav">
23+
</ul>
24+
</div>
25+
</div>
26+
</div>
27+
28+
<div class="container body-content">
29+
@RenderBody()
30+
<hr />
31+
<footer>
32+
<p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
33+
</footer>
34+
</div>
35+
36+
@Scripts.Render("~/bundles/jquery")
37+
@Scripts.Render("~/bundles/bootstrap")
38+
@RenderSection("scripts", required: false)
39+
</body>
40+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
Layout = "~/Views/Shared/_Layout.cshtml";
3+
}

0 commit comments

Comments
 (0)