<SfGrid @ref="Grid1" TValue="WeatherForecast" AllowSorting="true" AllowFiltering="true" AllowPaging="true" Toolbar="@(new List<string>() { "Cancel", "Update" })">
<SfDataManager @ref="dm" Url="/weatherforecast" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager>
<GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Normal"></GridEditSettings>
<GridColumns>
<GridColumn Field="@nameof(WeatherForecast.Id)" IsPrimaryKey="true"></GridColumn>
</GridColumns>
</SfGrid>
@code {
SfGrid<WeatherForecast> Grid1;
public SfDataManager dm { get; set; }
protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
(dm.DataAdaptor as ODataAdaptor).Options.UpdateType = HttpMethod.Put;
}
|
[HttpPut]
public async Task<IActionResult> Put([FromODataUri] int key, [FromBody] WeatherForecast update)
{
WeatherForecast entity = w.FirstOrDefault(x => x.Id == key);
if (entity != null) {
entity.Id = update.Id;
entity.Summary = update.Summary;
entity.Num = update.Num;
}
return await Task.FromResult(Ok());
} |
Dear support,
It seems that the proposed solution is not working anymore (Grid v20..4.0.49)
Severity Code Description Project File Line Suppression State
Error (active) CS1612 Cannot modify the return value of 'ODataAdaptor.Options' because it is not a variable.
Do you have an alternative?
Regards
Vincent
Hi Vincent,
Kindly use the below highlighted solution to change the Update Type as PUT in OdataV4 and revert us if you face any difficulties while implementing the below suggested solution.
<SfGrid @ref="Grid1" TValue="WeatherForecast" AllowSorting="true" AllowFiltering="true" AllowPaging="true" Toolbar="@(new List<string>() { "Cancel", "Update" })"> <SfDataManager @ref="dm" Url="/weatherforecast" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager> <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Normal"></GridEditSettings> <GridColumns> ... </GridColumns> </SfGrid>
@code { SfGrid<WeatherForecast> Grid1; public SfDataManager dm { get; set; } protected override void OnAfterRender(bool firstRender) { base.OnAfterRender(firstRender); RemoteOptions Rm = (dm.DataAdaptor as ODataV4Adaptor).Options; Rm.UpdateType = HttpMethod.Put; (dm.DataAdaptor as ODataV4Adaptor).Options = Rm;
} } |
Regards,
Monisha