Hi,
I have project where web api uses attribute routing and somehow rest binding doesn't work on my iggrid.
On other project without attribute routing it works and update method is called after editing ended.
What's the problem here? I'm getting 404 PUT localhost:53300/.../8281452
//controller // PUT api/values/5
[Route(Save)]
[HttpPut] public void Save (int id, [FromBody]Item value) { }
//js
$(function () { var dataURL = "">localhost:53300/.../values"; $("#grid1").igGrid({ dataSource: dataURL, primaryKey: "TIDnumber", restSettings: { update: { url: dataURL }, remove: { url: dataURL, batch: true }, create: { url: "dataURL", batch: true } }, autoGenerateColumns: false, height: "350px", width: "800px", columns: [ { headerText: "TIDnumber", key: "TIDnumber", dataType: "number" }, { headerText: "Description", key: "Description", dataType: "string" }, { headerText: "Quantity", key: "Quantity", dataType: "string" } ], features: [ { name: "Updating", editMode: 'row', editCellStarted: onEditCellStarted, editRowEnded: onEditCellEnded, columnSettings: [{ columnKey: 'TIDnumber', readOnly: true }, { columnKey: "Description", editorType: 'string', validation: true, editorOptions: { required: true } } ] } ] });
});
thank you
Hello Robson,
Thank you for the additional information.
Since a custom route is set for the controller the URI that matches this controller is now changed.
It will now be “api/values/Save” (prefixed with “api/values” from the RoutePrefix, and “Save” form the Route). Note that with the current route template (“Save”) the additional param {id}, which is needed to update the correct row by its id, is not defined and as such will not be passed to the controller. Consider changing the template so that it includes the id as part of the template so when send from the client it can be resolved and passed to the controller.
For example: “Save/{id}”
This would match requests in the following format: api/values/Save/<RowID>
To ensure the grid sends requests in the same format, make sure to set the update url correctly, for example:
update: { url: “/api/values/Save” }
You can read more about attribute routing and how it builds the URIs here: https://docs.microsoft.com/en-us/aspnet/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2
And you can also read about the grid rest settings that determine the url the request are send to here: https://www.igniteui.com/help/iggrid-rest-updating
Let me know if you have any additional questions or concerns.
Regards,
Maya Kirova
BTW I tried template option as well and didn't work
sorry, this was typo, of course it's: : [Route("Save")].
as long as I put even empty Route[""] api update controller is not called
and getting error 405 , PUT not allowed or 404,
any example how does it work with Attribute Routing?
with ["HttpPut"] alone works fine
Typically the Route attribute accepts a string, which is the URI template for the route. For example:
[Route("api/values")]
In your case you are passing something called “Save”: [Route(Save)]. Could you let me know what the value of Save is?
I’m looking forward to your reply.
Maya
Hi Maya,
I have standard routing config, no custom routes:
config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } );
but I have [RoutePrefix("api/values")] defined
so on update method is only [Route(Save)]
I tried to directly put whole update url in restSetting but didn't work, 404 getting