All Components

New to Telerik UI for ASP.NET MVC? Download free 30-day trial

ASP.NET MVC Grid Custom Editing

Loading Demo...
  • EXAMPLE
  • VIEW SOURCE
  • Change Theme
    default
    Default Theme
    • Main
    • Main Dark
    • Nordic
    • Ocean Blue
    • Ocean Blue A11Yaccessibility
    • Purple
    • Turquoise
    Bootstrap Theme
    • Main
    • Bootstrap 3
    • Bootstrap 3 Dark
    • Main Dark
    • Nordic
    • Turquoise
    • Turquoise Dark
    • Urban
    • Vintage
    Material Theme
    • Main
    • Arctic
    • Lime Dark
    • Main Dark
    • Material 2
    • Material 2 Dark
    • Nova
    Classic Theme
    • Main
    • Green
    • Green Dark
    • Lavender
    • Lavender Dark
    • Main Dark
    • Metro
    • Metro Dark
    • Moonlight
    • Opal
    • Opal Dark
    • Silver
    • Silver Dark
    • Uniform
    Fluent Theme
    • Main
editing_custom.cshtml
Editing_CustomController.cs
ProductService.cs
ClientCategory.cshtml
CategoryViewModel.cs
ProductViewModel.cs

Also available for:

CLIENT-SIDE API SERVER-SIDE API

Description

Some scenarios require theTelerik UI for ASP.NET MVC Data Grid not only visualize data in a table structure, but also to support editing and validation before users save changes.

TheTelerik UI for ASP.NET MVC Grid allows you to implement CRUD data-editing operations by setting its data source. To enable the data-editing capabilities of the component:

  1. Set theEditable configuration property of the Grid—.Editable(editable => editable.Mode(GridEditMode.InCell)).
  2. Specify a unique field in theModel as theDataSource.Model.Id.
  3. Configure the DataSource of the Data Grid for performing CRUD data operations by defining itsRead,Create,Update, andDestroy methods.

To allow the insertion of new Data Grid records, you need to add theNew Record button in the toolbar of the component—.ToolBar(toolbar => toolbar.Create()).

To enable theDelete command on each row, insert a new column—columns.Command(command => { command.Destroy(); });.

This demo shows how to further customize the editor for theCategory field which is an object (a complex type). To make sure that the Data Grid uses the custom editor, add the editor to the~Views\\Shared\\EditorTemplates folder, for example,@(Html.Kendo().DropDownListFor(m => m).

To ensure that the Grid invokes the custom editor:

  1. Decorate themodel property with theUIHint attribute.
    [UIHint("ClientCategory")]
    public CategoryViewModel Category { get; set;}
  2. Specify a default value that will be used initially when an item will be created:
    model.Field(p => p.Category).DefaultValue(ViewData["defaultCategory"] as Kendo.Mvc.Examples.Models.CategoryViewModel);

For more information about the editing capabilities, refer to theofficial Telerik UI for ASP.NET MVC Data Grid product documentation on the available data-editing approaches.

Additional Apps

This Grid example is part of a unique collection of hundreds of ASP.NET MVC demos, with which you can see allTelerik ASP.NET MVC components and their features in action. View the source code of the demos from the library or directly adapt, and edit them and their theme appearance in theThemeBuilder.

Support & Learning Resources

Additional Resources