Skip to content

DevExpress-Examples/asp-net-mvc-grid-edit-form-template-for-new-rows

Repository files navigation

Grid View for ASP.NET MVC - How to create a custom edit form for new rows

This example demonstrates how to specify the grid's edit form template for newly inserted rows.

Edit form template for new rows

Overview

Handle the grid's client-side BeginCallback event to determine the grid's edit mode after a callback.

function OnBeginCallback(s, e) {
    var isNewRowNow = s.IsNewRowEditing();
    var isSwitchToNewRow = (e.command == 'ADDNEWROW');
    var IsCancelEdit = (e.command == 'CANCELEDIT');
    var IsSwitchToEdit = (e.command == 'STARTEDIT');
    var result = (isSwitchToNewRow * !IsCancelEdit + isNewRowNow) * !IsSwitchToEdit;
    e.customArgs['IsNewRow'] = Boolean(result);
}

Process the received value in the Controller and use the ViewBag mechanism to pass the value to the View.

[HttpPost, ValidateInput(false)]
public ActionResult GridViewEditingPartial(bool IsNewRow) {
    if (IsNewRow)
        ViewBag.IsNewRow = true;
    return PartialView(list.GetPersons());
}

[HttpPost, ValidateInput(false)]
public ActionResult EditingAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] Person person) {
    ViewBag.IsNewRow = true;
    // ...
}

Call the grid's SetEditFormTemplateContent method to create an edit form template based on the ViewBag value.

if(ViewBag.IsNewRow != null)
    if(ViewBag.IsNewRow == true)
        settings.SetEditFormTemplateContent(c => {
            ViewContext.Writer.Write("EditForm Template Content");
        });

Files to Review

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Specify the grid's edit form template for newly inserted rows.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •