File tree Expand file tree Collapse file tree 4 files changed +77
-0
lines changed
Telerik.Examples.Mvc/Telerik.Examples.Mvc Expand file tree Collapse file tree 4 files changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using Microsoft . AspNetCore . Mvc ;
5+ using Telerik . Examples . Mvc . Models ;
6+
7+ namespace Telerik . Examples . Mvc . Controllers . Grid
8+ {
9+ public class ViewComponentController : Controller
10+ {
11+ public IActionResult ViewComponent ( )
12+ {
13+ var random = new Random ( ) ;
14+
15+ var data = Enumerable . Range ( 1 , 10 )
16+ . Select ( x => new Product
17+ {
18+ Discontinued = x % 2 == 1 ,
19+ ProductID = x ,
20+ ProductName = "Product " + x ,
21+ UnitPrice = random . Next ( 1 , 1000 ) ,
22+ UnitsInStock = random . Next ( 1 , 1000 ) ,
23+ UnitsOnOrder = random . Next ( 1 , 1000 )
24+
25+ } )
26+ . ToList ( ) ;
27+
28+ return View ( data ) ;
29+ }
30+ }
31+ }
Original file line number Diff line number Diff line change 1+ using Microsoft . AspNetCore . Mvc ;
2+ using System . Collections ;
3+ using System . Collections . Generic ;
4+ using System . Threading . Tasks ;
5+ using Telerik . Examples . Mvc . Models ;
6+
7+ namespace Telerik . Examples . Mvc . ViewComponents
8+ {
9+ public class GridViewComponent : ViewComponent
10+ {
11+ public async Task < IViewComponentResult > InvokeAsync ( IEnumerable < Product > gridModel )
12+ {
13+ return View ( "default" , gridModel ) ;
14+ }
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ @{
2+ ViewData [" Title" ] = " View Component" ;
3+ }
4+ <h3 >@ViewData ["Title"]</h3 >
5+ @model IEnumerable <Product >
6+
7+ @await Component.InvokeAsync("Grid", Model)
Original file line number Diff line number Diff line change 1+ @using Telerik .Examples .Mvc .Models
2+
3+ @model IEnumerable <Product >
4+
5+ @( Html .Kendo ().Grid (Model )
6+ .Name (" grid" )
7+ .DataSource (dataSource => dataSource
8+ .Ajax ()
9+ .PageSize (5 )
10+ .ServerOperation (false )
11+ )
12+ .Columns (columns =>
13+ {
14+ columns .Bound (product => product .ProductID );
15+ columns .Bound (product => product .ProductName );
16+ columns .Bound (product => product .UnitsInStock );
17+ columns .Bound (product => product .Discontinued );
18+ })
19+ .Pageable ()
20+ .Sortable ()
21+ .Filterable ()
22+ .Groupable ()
23+ )
You can’t perform that action at this time.
0 commit comments