This example illustrates how to specify a grid's EditForm template only when adding a new row and leave the default template when editing a row. Perform the following steps to accomplish this task:
1. Handle the MVCxClientGridView.BeginCallback event to determine which mode the grid will be in after a callback:
[JScript]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);}
2. Process the received value in the controller and pass it to the view using ViewBag:
[C#][HttpPost,ValidateInput(false)]publicActionResultGridViewEditingPartial(boolIsNewRow){if(IsNewRow) ViewBag.IsNewRow=true;returnPartialView(list.GetPersons());}[HttpPost,ValidateInput(false)]publicActionResultEditingAddNew([ModelBinder(typeof(DevExpressEditorsBinder))]Personperson){ViewBag.IsNewRow=true;...}
3. After that, you can create a template based on the ViewBag value:
[C#]if(ViewBag.IsNewRow!=null) if(ViewBag.IsNewRow==true) settings.SetEditFormTemplateContent(c=> { ViewContext.Writer.Write("EditForm Template Content"); });