UrlAdaptor edit value null

Hello

I am using ASP.NET CORE EJ 2 version 16.1.0.34 (nuget package).

Using the grid with the UrlAdaptor I noted some strange behaviour (this happens both for Razor and Tag Helper).

  • When adding columns to the grid, no values will be displayed if the field name starts with a capital letter. It only displays values if the name starts with a lower case letter (even though my data type's properties all start with capital letters).
  • When editing records, the corresponding url action is called correctly, but the value (e.g. when updating) is always null or empty. I used the example here https://ej2.syncfusion.com/16.1.32/aspnet/documentation/grid/edit.html and only updated the field names to match my objects. 

Could you provide me with help to solve these problems?


Kind regards
Phil

7 Replies

DR Dhivya Rajendran Syncfusion Team April 18, 2018 01:08 PM UTC

Hi Phil, 

Thanks for contacting Syncfusion support. 

Query1: it only displays values if the name starts with a lower case letter 

We have analyzed your problem this is because of the JSON serialize setting no longer default to the DefaultContractResolver instead it defaults to the CamelCasePropertyNamesContractResolver. You can use the following code in your Startup.cs file to resolve your problem.  
 
  public void ConfigureServices(IServiceCollection services)  
        {  
            services.AddMvc().  
            AddJsonOptions(options =>  
                {  
                    // JSON serialization not defaulting to default?  
                    options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();  
                });  
        }  
 
Query2: When editing records, the corresponding url action is called correctly? 
We have analyzed you query, we have performed insert and delete operation with the help of CRUDModel this might resolve your problem. The edited data will be bounded to the value property of the CRUDModel class. 
Kindly refer to the below code example for more information. In this below sample we have perform CRUD operation using Url Adaptor in Grid. 
<ejs-grid id="Grid" toolbar="@(new List<string>() { "Add", "Delete","Edit","Update", "Cancel" })" allowPaging="true"> 
        <e-datamanager url="/Home/UrlDatasource" adaptor="UrlAdaptor" insertUrl="/Home/Insert" updateUrl="/Home/Update" removeUrl="/Home/Delete"></e-datamanager> 
        <e-grid-editSettings allowDeleting="true" allowEditing="true" allowAdding="true"></e-grid-editSettings> 
        <e-grid-columns> 
            <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" validationRules="@(new { required=true})" width="120"></e-grid-column> 
        . . . . . 
        </e-grid-columns> 
    </ejs-grid> 

Controller: 
        //Delete the record 
        public ActionResult Delete([FromBody]CRUDModel<OrdersDetails> value) 
        { 
                    OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().Where(or => or.OrderID == int.Parse(value.key.ToString())).FirstOrDefault()); 
            return Json(value); 
        } 
 
        public class CRUDModel<T> where T : class 
        { 
            public string action { get; set; } 
 
            public string table { get; set; } 
 
            public string keyColumn { get; set; } 
 
            public object key { get; set; } 
 
            public T value { get; set; } 
             
            . . . . . . 
        } 
    } 



Please get back to us if you need further assistance. 
Regards, 
R.Dhivya 



UN Unknown April 19, 2018 10:20 AM UTC

Thanks to your suggestion the Grid Field names work now as expected, thank you.

I tried your approach with the CRUDModel class and it worked, the value.value property contains the data entered in the grid.
The Url Adaptor part of the grid documentation (https://ej2.syncfusion.com/16.1.32/aspnet/documentation/grid/edit.html?syntax=tag#url-adaptor) seems to indicate that it should be possible to use CRUD operations without wrapping the model in another object.

Could you please provide me with a link to the documentation where your approach is documented?


Kind regards


IR Isuriya Rajan Syncfusion Team April 20, 2018 09:25 AM UTC

Hi Phil,  
 
We can also achieve this without using CRUDModel as provided in the below documentation link. 
 
 
 
Thanks for your suggestion we will include this in our documentation . 
 
Regards, 
Isuriya R 



UN Unknown April 20, 2018 09:45 AM UTC

I tried doing that without the CRUDModel, but then all parameters of the object are always null (as described in the initial post).

That's why I would like to see the documentation where the approach with the CRUDModel and all corresponding parameters are defined.
Could you please provide me with a link to the documentation where the CRUDModel is used?

Kind regards


IR Isuriya Rajan Syncfusion Team April 24, 2018 10:01 AM UTC

Hi Phil,  
                         
On further validation on the mention issue, we have found that JsonInputFormatter from JSON.Net, is used for model binding in ASP.Net Core, which prevents the individual usage of property name as parameter. So for this, we need to access the request parameter at the server side using the class structure same as the posted data. Please use the CRUDModel for this as provided in the previous update.  
 
Currently we don’t have documentation for this. We will include the details about CRUDModel in the documentation which will be refreshed in any of the upcoming release. Also if you require further assistance on using CRUDModel. please let us know. We are glad to help you out.  
  
Regards, 
Isuriya R 



UN Unknown April 24, 2018 10:09 AM UTC

Thanks for the update.

I am glad to see, that this will be documented some time in the future.

Could you add a remark in the current documentation that the CRUDModel should be used and that it will be documented some time in the furure?
This might prove quite useful for other people running into this issue.

Also, could you please post an update in this thread once the CRUDModel is documented?


For me this issue is solved. Thanks again for your help.


Kind regards
Phil


IR Isuriya Rajan Syncfusion Team April 25, 2018 11:14 AM UTC

Hi Phil, 
 
Thanks for your suggestion. We will include the section about CRUDModel in our documentation.   
 
Once the documentation is refreshed live, we will let you know. 
 
Regards, 
Isuriya R 
 


Loader.
Up arrow icon