Error posting new content in Grid (OData)

Hello,

Please look at the following code snip:

<SfGrid ID="DetailProgramsGrid" @ref="@DetailProgramsGrid" TValue="CustomerLoyaltyPrograms" AllowResizing="true" AllowSorting="true" AllowReordering="true"
Toolbar="@DetailProgramsTool"
Query="@(new Query().AddParams("$expand","customerloyaltyprogrampointsprogramnavigation").AddParams("$filter",$"customerloyaltyprogramsperson eq {selectedPersonId}"))">
<GridPageSettings PageSize="5"></GridPageSettings>
<GridEvents OnActionBegin="ActionBeginProgramsDetailHandler" RowSelected="DetailProgramsRowSelectHandler" TValue="CustomerLoyaltyPrograms"></GridEvents>
<SfDataManager Url=@($"{apiURL}/customerloyaltyprograms") Adaptor="Adaptors.ODataV4Adaptor" CrossDomain="true"></SfDataManager>

When I try to add a record, the OData API responds with the following error:

message: "The query specified in the URI is not valid. The requested resource is not a collection. Query options $filter, $orderby, $count, $skip, and $top can be applied only on collections."

I see that the POST request made from the Grid is including the $expand and $filter params. Is this se source of the error? Is there any way not to send this two params in the POST request?

I tested in postman without the $expand and $filter params and it works ok.

Thanks,

erick




3 Replies 1 reply marked as answer

JP Jeevakanth Palaniappan Syncfusion Team July 24, 2020 04:23 PM UTC

Hi Erick, 

We have checked the reported issue and we suspect that the issue is due to binding $expand and $filter in the Addparams method of Query class. Instead we suggest you to use the Expand and Where method of Query class to resolve this issue. Please refer the below code snippet. 

<SfGrid ID="DetailProgramsGrid" @ref="@DetailProgramsGrid" 
Query="@(new Query().Expand(new List<string>() {"Id"}).Where("Id", "equal", 1))"> 
     <GridPageSettings PageSize="5"></GridPageSettings> 
     <GridEvents OnActionBegin="ActionBeginProgramsDetailHandler"RowSelected="DetailProgramsRowSelectHandler" > 
    </GridEvents> 
.. 
.. 
</SfGrid> 

Also refer our UG documentation on complex binding for your reference 


Kindly get back to us if you have any other concerns.  

Regards, 
Jeevakanth SP. 


Marked as answer

ER Erick July 25, 2020 03:33 AM UTC

Works Great. Thank you very much.


RN Rahul Narayanasamy Syncfusion Team July 27, 2020 05:22 AM UTC

Hi Erick, 
 
Thanks for the update. 
 
We are happy to hear that the provided solution was helpful to resolve your problem. 
 
Please get back to us if you need further assistance. 
 
Regards, 
Rahul 


Loader.
Up arrow icon