c# - ASP.NET Web API 2 operation DELETE with guid -
i have simple method:
public async task<string> delete(guid id) { var success = await productfacade.deleteproductasync(id); if (!success) { throw new httpresponseexception(httpstatuscode.notfound); } return $"deleted product id: {id}"; }
but when try make delete request fiddler, says:
{"message":"the request invalid.","messagedetail":"the parameters dictionary contains null entry parameter 'id' of non-nullable type 'system.guid' method 'system.threading.tasks.task`1[system.string] delete(system.guid)' in 'demoeshop.webapi.controllers.productscontroller'. optional parameter must reference type, nullable type, or declared optional parameter."}
delete request is: http://localhost:56118/api/products/aa16dc64-5c07-40fe-a916-175165b9b90
really interesting put method uses guid parameter works. here is:
public async task<string> put(guid id, [frombody]productdto product) { if (!modelstate.isvalid) { throw new httpresponseexception(httpstatuscode.badrequest); } var success = await productfacade.editproductasync(product); if (!success) { throw new httpresponseexception(httpstatuscode.notfound); } return $"updated product id: {id}"; }
do have idea why delete not work?
your guid sending via fiddler contains 31 hex digit instead of 32.
http://localhost:56118/api/products/aa16dc64-5c07-40fe-a916-175165b9b90
the last fifth segment should have 12 hex digits, have 11. cause guid.parse()
fail.
Comments
Post a Comment