Edit data not reflected in datasource

Hi,

I am developing a preschool app using ASP.NET Core 3.1 using razor for views/view-models. Whilst creating a child's admission record, I am trying to record the parents/guardians' information using a SF Grid allowing user to add rows of parent/guardian information. I am using the built-in grid commands of Add, Edit, Delete and not any fancy custom command handling. However, during the POST operation, the view is sending NULL as the Parent collection inside the Admission object. Please help.

Model
-----
    public class Admission
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public DateTime DateOfBirth { get; set; }
        public List Parents { get; set; }
        public DateTime AdmittedOn { get; set; }

        [JsonConverter(typeof(StringEnumConverter))]
        public AdmissionStatus Status { get; set; }
    }

    public class Parent
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Occupation { get; set; }
        public string EmaildId { get; set; }
    }

----
ViewModel
----
       
           
           
               
               
               
           
           
               
               
               
           
           
               
                   
                              dataSource="@Model.Admission.Parents"
                              allowResizing="true"
                              gridLines="Both"
                              toolbar="@(new List() { "Add", "Edit", "Delete", "Update", "Cancel" })">
                       
                                             allowDeleting="true"
                                             allowEditing="true"
                                             newRowPosition="Bottom"
                                             showDeleteConfirmDialog="true"
                                             mode="Normal"/>
                       
                           
                           
                           
                       
                   
               

               
                   
                   
                   
               
               
                   
               
       

----
ViewModel
----
    public class CreateModel : PageModelBase
    {
        public IActionResult OnGet()
        {
            Admission = new Admission
            {
                Parents = new List(),
            };

            return Page();
        }

        [BindProperty]
        public Admission Admission { get; set; }

        public async Task OnPostAsync()
        {
            AppDataContext.Admissions.Add(Admission);
            await AppDataContext.SaveChangesAsync();

            return RedirectToPage("./Index");
        }
    }


1 Reply

TS Thiyagu Subramani Syncfusion Team April 13, 2020 01:39 PM UTC

Hi Deepak, 

Thanks for contacting Syncfusion forum. 

Based on your reported information we suspect your reported issue “Using the built-in grid commands of Add, Edit, Delete and not any fancy custom command handling. However, during the POST operation, the view is sending NULL” is you sending post for Add, Edit, Delete action to server side but view sends the NULL . For this case we recommend to use our default adaptors. In this adaptors in-built we have handled Add, Edit, Delete post actions. 

Please refer the below link. 




For more reference we have prepared sample in razor page  with URL adaptors. 


Please get back to us, if you need any further assistance. 

Regards, 
Thiyagu S. 


Loader.
Up arrow icon