We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

editing doesnt work when columns are auto generated

Hi,

if I dont define like below, if i try to edit any row not first row, it always edits first row. Beside that I try to persist data to server but my item object is always empty. is there something I do wrong?

thanks,

Emil

@(Html.EJ().Grid<Models.Db.App>("Grid")
                    .Datasource((IEnumerable<Models.Db.Item>)Model) 
               .Datasource(dataSource => dataSource.Json((IEnumerable<Models.Db.Item>)Model).UpdateURL("Items/Edit")
                .InsertURL("Items/Create").RemoveURL("Items/Delete").Adaptor(AdaptorType.RemoteSaveAdaptor))
       .AllowSorting()
       .AllowFiltering()

         .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().ShowDeleteConfirmDialog(); })
          .ToolbarSettings(toolbar =>
          {
              toolbar.ShowToolbar().ToolbarItems(items =>
              {
                  items.AddTool(ToolBarItems.Add);
                  items.AddTool(ToolBarItems.Edit);
                  items.AddTool(ToolBarItems.Delete);
                  items.AddTool(ToolBarItems.Update);
                  items.AddTool(ToolBarItems.Cancel);
              });
          })
)


   public async Task<ActionResult> Edit(Item item)
        {
            if (ModelState.IsValid)
            {
                 
            }
            return View(item);
        }

2 Replies

EM Emil November 30, 2018 04:55 PM UTC

Ok I figured out. parameter name should value always. i think that this needs to be highlighted in the documentation better for the newbies like me.


VN Vignesh Natarajan Syncfusion Team December 3, 2018 07:12 AM UTC

Hi Emil, 
 
Thanks for using Syncfusion products. 
 
Query1: “if i try to edit any row not first row, it always edits first row” 
 
From your query, we understand that you are not able to edit the Grid rows properly. From your code example, we have found that you rendered the Grid with autoGenerated column. So IsPrimaryKey property is not assigned to any of the available column. This is the cause of the issue. 
 
Refer below link for our knowledge base document for the importance of PrimaryKey property in ejGrid while editing. 
 
 
Also refer the below UG document how to define the PrimaryKey for autogenerated column.  
 
 
Query2: Beside that I try to persist data to server but my item object is always empty. ” 
 
By default while editing, we have passed the model values using property called “value”. So we suggest you to define the parameter as value in the server side.  
 
Refer the modified code example 
 
 public async Task<ActionResult> Edit(Item value) 
        { 
            if (ModelState.IsValid) 
            { 
                  
            } 
            return View(item); 
        } 
 
 
Refer our UG documentation for your reference 
 
 
Please get back to  us if you have further queries. 
 
Regards, 
Vignesh Natarajan 


Loader.
Live Chat Icon For mobile
Up arrow icon