ASP.NET MVC Controls > Controls > CollectionView > Quick Start |
This section describes how to useCollectionView with FlexGrid control in your MVC web application.
This topic comprises of three steps:
The following image shows how the FlexGrid appears after completing the steps above:
Create a new MVC application using the ComponentOne templates. For more information about creating an MVC application, see Configuring your MVC Application topic.
![]() |
The example uses C1NWind database. The C1NWind.mdf file is available on your system in C:\Users\<username>\Documents\ComponentOne Samples\ASP.NET MVC\MVC\MvcExplorer\App_Data. |
AppData
folder in the Solution Explorer.Models|Add New Item|Data
, and select ADO.NET Entity Data Model.Tables
, and click Finish.If you can see C1NWind.edmx added to your project under the Models folder, you have successfully configured the datasource for your application.
Back to TopComplete the following steps to initialize a FlexGrid control.
Add a new Controller
Default1Controller
).C# |
Copy Code
|
---|---|
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using CollectionView_EN.Models; using C1.Web.Mvc.Grid; using C1.Web.Mvc; using C1.Web.Mvc.Serializition; using System.Data.Entity.Validation; using System.Data.Entity; using System.Data; |
![]() |
Note: Replace CollectionView_EN.Models; with <YourMVCApplicationName>.Models; in the references. |
IndexController.cs
C# |
Copy Code
|
---|---|
//Define datasource for FlexGrid private C1NWindEntities db = new C1NWindEntities(); public ActionResult Index() { return View(); } //Instantiate a JSON request public ActionResult GridReadCategory([C1JsonRequest] CollectionViewRequest<Category> requestData) { return this.C1Json(CollectionViewHelper.Read(requestData, db.Categories)); } |
Add a View for the controller:
Default1Controller
) to open it.Index()
.Index.cshtml
to open it.In this example, the GridReadCategory action of controller is assigned to Bind property of FlexGrid' ItemSource to populate data.
Razor (Index.cshtml) |
Copy Code
|
---|---|
@(Html.C1().FlexGrid().Id("fGRCView").AutoGenerateColumns(false).AllowAddNew(true) .AllowSorting(true).CssClass("grid") .Columns(columns => columns .Add(c => c.Binding("CategoryID")) .Add(c => c.Binding("CategoryName")) .Add(c => c.Binding("Description").Width("500"))) .Bind( ib => ib.Bind(Url.Action("GridReadCategory")) ) ) |