CollectionView
CollectionView
Overview
This view shows basic features of CollectionView ASP.NET MVC.
Features
Sample
Settings
Description
This view shows basic features of CollectionView ASP.NET MVC.
The refreshOnEdit property determines whether the CollectionView should automatically refresh its results (by applying the sort, filter, and grouping operations) after items are edited. This property is set to true by default, which ensures the collection is always sorted, filtered, and grouped correctly after any edit operations.
Source
IndexController.cs
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using C1.Web.Mvc; using C1.Web.Mvc.Serialization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Primitives; using MvcExplorer.Models; namespace MvcExplorer.Controllers { public partial class CollectionViewController : Controller { private readonly ControlOptions _optionsModel = new ControlOptions { Options = new OptionDictionary { {"Refresh On Edit", new OptionItem {Values = new List<string> {"True", "False"}, CurrentValue = "True"}} } }; public ActionResult Index(IFormCollection collection) { _optionsModel.LoadPostData(collection); ViewBag.DemoOptions = _optionsModel; return View(); } public ActionResult Index_Bind([C1JsonRequest] CollectionViewRequest<Sale> requestData) { var extraData = requestData.ExtraRequestData .ToDictionary(kvp => kvp.Key, kvp => new StringValues(kvp.Value.ToString())); var data = new FormCollection(extraData); _optionsModel.LoadPostData(data); var model = Sale.GetData(500); return this.C1Json(CollectionViewHelper.Read(requestData, model)); } } }
Index.cshtml
@using C1.Web.Mvc.Grid @model IEnumerable<Sale> @{ ControlOptions optionsModel = ViewBag.DemoOptions; ViewBag.DemoSettings = true; } <c1-items-source id="CVService" initial-items-count="500" read-action-url="@Url.Action("Index_Bind")" refresh-on-edit="@Convert.ToBoolean(optionsModel.Options["Refresh On Edit"].CurrentValue)" disable-server-read="true"></c1-items-source> <c1-flex-grid id="FlexGridCV" items-source-id="CVService" auto-generate-columns="false" sorting-type="SingleColumn" class="grid"> <c1-flex-grid-column binding="ID"></c1-flex-grid-column> <c1-flex-grid-column binding="Start" format="MMM d yy"></c1-flex-grid-column> <c1-flex-grid-column binding="End" format="HH:mm"></c1-flex-grid-column> <c1-flex-grid-column binding="Country"></c1-flex-grid-column> <c1-flex-grid-column binding="Product"></c1-flex-grid-column> <c1-flex-grid-column binding="Color"></c1-flex-grid-column> <c1-flex-grid-column binding="Amount" format="c"></c1-flex-grid-column> <c1-flex-grid-column binding="Amount2" format="c"></c1-flex-grid-column> <c1-flex-grid-column binding="Active"></c1-flex-grid-column> </c1-flex-grid> @section Summary{ <p>@Html.Raw(CollectionViewRes.Index_Text0)</p> } @section Settings{ @await Html.PartialAsync("_OptionsMenu", optionsModel) } @section Description{ <p>@Html.Raw(CollectionViewRes.Index_Text0)</p> <p>@Html.Raw(CollectionViewRes.Index_Text1)</p> }
Documentation