ASP.NET oData patchValue obtained from Angular, nothing

I am developing an application with Angular interface and ASP.NET back side using oData and Oracle. I am at the point where I am trying to correct the entries on the rear panel. I use the generic template code on the back of my controller, and the patch method is as follows:

<AcceptVerbs("PATCH", "MERGE")> Async Function Patch(<FromODataUri> ByVal key As Decimal, ByVal patchValue As Delta(Of FTP_ORDERS)) As Task(Of IHttpActionResult) Validate(patchValue.GetEntity()) If Not ModelState.IsValid Then Return BadRequest(ModelState) End If Dim fTP_ORDERS As FTP_ORDERS = Await db.FTP_ORDERS.FindAsync(key) If IsNothing(fTP_ORDERS) Then Return NotFound() End If patchValue.Patch(fTP_ORDERS) Try Await db.SaveChangesAsync() Catch ex As DbUpdateConcurrencyException If Not (FTP_ORDERSExists(key)) Then Return NotFound() Else Throw End If End Try Return Updated(fTP_ORDERS) End Function 

On the Angular side, I use a service based on $ resource to send the update. The code calling the resource is as follows:

  (new FTPOrderService({ "key": vm.ID, "data": vm }, vm)) .$patch() .then(function (data) { alert("Order Saved!"); }, function (error) { debugger; } ); 

The service is defined using:

 .factory('FTPOrderService', function ($resource) { var odataUrl = '../odata/FTP_ORDERS'; var results = $resource('', {}, { 'patch': { method: 'PATCH', params: { key: '@key', }, url: odataUrl + '(:key)' } }); return results; }) 

I also tried:

 (new FTPOrderService({ "key": vm.ID, }, vm)) .$patch(vm) .then(function (data) { alert("Order Saved!"); }, function (error) { debugger; } ); 

and get the same results.

I believe that I configured Angular to send data correctly:

 .config(['$httpProvider', function ($httpProvider) { $httpProvider.defaults.headers.patch = { 'Content-Type': 'application/json;charset=utf-8' }; }]) 

The debugger shows that I am calling the URL with the corresponding key added to it in parens, and the request payload is as follows:

 {key: "1239990990", data: {loading: false, selectedRow: {}, lineItems: [,…], orderId: "1239990990",…}} data: {loading: false, selectedRow: {}, lineItems: [,…], orderId: "1239990990",…} key: "1239990990" 

Any idea what I'm missing? There are many examples that use direct calls to $ http.post and a few for .patch, but nothing is used using $ resource.

+2
angularjs odata
source share
1 answer

I'm not quite sure what the cause of this problem is, but tracking it, I found that with interruptions the object did not receive the patch method in .NET. The object I am passing is especially heavy, and what I walked by default was actually heavier than what the ASP.NET application requires. Adding code before calling the patch to build an object that meets the minimum requirements solved the problem.

+1
source share

All Articles