Hi.
I am trying to bind data on the sfgrid from a webapi that returns a Json as you can see below, but the component is returning the flowing error: Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Syncfusion.Blazor.Data.OData`1[HPReconnectV3.Data.VendorContractMarkups]' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
The code I am using:
<SfGrid TValue="VendorContractMarkups " AllowResizing="true">
<GridEvents TValue="VendorContractMarkups" OnActionFailure="@ActionFailure"></GridEvents>
<SfDataManager Url="https://localhost:44325/api/VendorContractMarkup?MemberId=1566&VendorProductId=421275" CrossDomain="true" Adaptor="Adaptors.ODataAdaptor"></SfDataManager>
<GridPageSettings PageSize="10"></GridPageSettings>
<GridColumns>
<GridColumn Field="@nameof(VendorContractMarkups.Distributor)" HeaderText="Distributor" TextAlign="@TextAlign.Left" Width="200"> </GridColumn>
<GridColumn Field="@nameof(VendorContractMarkups.Warehouse)" HeaderText="Warehouse" TextAlign="@TextAlign.Left" Width="190"> </GridColumn>
<GridColumn Field="@nameof(VendorContractMarkups.ProductCode)" HeaderText="Product Code" TextAlign="@TextAlign.Left" Width="80"> </GridColumn>
<GridColumn Field="@nameof(VendorContractMarkups.Markup)" HeaderText="Markup %" TextAlign="@TextAlign.Left" Width="80"> </GridColumn>
<GridColumn Field="@nameof(VendorContractMarkups.FinalPrice)" HeaderText="Final Price" Format="C2" TextAlign="@TextAlign.Left" Width="80"> </GridColumn>
<GridColumn Field="@nameof(VendorContractMarkups.NextPrice)" HeaderText="Next Price" Format="C2" TextAlign="@TextAlign.Left" Width="80"> </GridColumn>
<GridColumn Field="@nameof(VendorContractMarkups.NextPriceDate)" HeaderText="Next Price Date" TextAlign="@TextAlign.Left" Width="80"> </GridColumn>
</GridColumns>
</SfGrid>
@code {
.....
private SfGrid<VendorContractMarkups> PriceGrid;
IEnumerable<VendorContractMarkups> vendorcontractmarkups;
public class VendorContractMarkups
{
public string Distributor { get; set; }
public string Warehouse { get; set; }
public string ProductCode { get; set; }
private float _markup;
public Nullable<float> Markup
{
get
{
if (_markup != 0)
return _markup;
else
return null;
}
set
{
_markup = (float)value;
}
}
private float _finalprice;
public Nullable<float> FinalPrice
{
get
{
if (_finalprice != 0)
return _finalprice;
else
return null;
}
set
{
_finalprice = (float)value;
}
}
private float _nextprice;
public Nullable<float> NextPrice
{
get
{
if (_nextprice != 0)
return _nextprice;
else
return null;
}
set
{
_nextprice = (float)value;
}
}
public string NextPriceDate { get; set; }
}
}
Thank you.
Leo
public async Task<object> Get(int? code){
..
var queryString = Request.Query;
if (queryString.Keys.Contains("$inlinecount"))
{
StringValues Skip;
StringValues Take;
int skip = (queryString.TryGetValue("$skip", out Skip)) ? Convert.ToInt32(Skip[0]) : 0;
int top = (queryString.TryGetValue("$top", out Take)) ? Convert.ToInt32(Take[0]) : data.Count();
var count = data.Count();
return new { Items = data.Skip(skip).Take(top), Count = count };
}
else
{
return data;
}
}
|
Thank you Jeevakanth .
It is working.
Best regards,
Leo