Hi, I'm having an issue with my Kendo Grid where when the update event hits my web api controller, the model is showing but all the values are null or 0. I've done this months back with another company and I got it working just fine, but this time around, it's not working.
Here's the relevant snippet on the controller end (and yes, it's hitting right correct controller).
1.
[HttpPut]
2.
[ResponseType(
typeof
(spLineItemsGetAllForOrder_Result))]
3.
[Route(
"Orders/UpdateLineItems"
)]
4.
public
int
UpdateLineItems([FromBody]spLineItemsGetAllForOrder_Result models)
5.
{
Even without line 2, the responseType, still doesn't change anything. A long time ago, when we were first having this problem with another company, the key factor was to place the [FromBody] attribute in there. I did that, doesn't help here.
Here's my JS for the grid.
01.
$(document).ready(
function
() {
02.
var
crudServiceBaseUrl =
"http://localhost:56291/"
,
03.
dataSource =
new
kendo.data.DataSource({
04.
transport: {
05.
read: {
06.
url: crudServiceBaseUrl +
'Orders/GetLineItemsForOrder/'
+ Cookies.get(
"ponum"
),
07.
dataType:
"json"
,
08.
type:
'GET'
,
09.
contentType:
'application/json; charset=utf-8'
10.
},
11.
create: {
12.
url: crudServiceBaseUrl +
'Orders/InsertLineItems/'
+ Cookies.get(
"ponum"
),
13.
dataType:
"json"
,
14.
type:
'POST'
,
15.
contentType:
'application/json; charset=utf-8'
16.
},
17.
update: {
18.
url: crudServiceBaseUrl +
"Orders/UpdateLineItems"
,
19.
dataType:
"json"
,
20.
type:
"PUT"
,
21.
contentType:
'application/json; charset=utf-8'
22.
},
23.
destroy: {
24.
url: crudServiceBaseUrl +
'Orders/DeleteLineItem/'
,
25.
datatype:
"json"
,
26.
type:
'DELETE'
,
27.
contentType:
'application/json; charset=utf-8'
28.
},
29.
parameterMap:
function
(options, operation) {
30.
if
(operation !==
"read"
&& options.models) {
31.
32.
return
{ models: kendo.stringify(options.models) };
33.
34.
}
35.
}
36.
},
37.
batch:
true
,
38.
pageSize: 20,
39.
schema: {
40.
model: {
41.
id:
"LineItemPK"
,
42.
fields: {
43.
LineItemPK: { editable:
false
, nullable:
true
},
44.
Quantity: { editable:
true
, type:
"number"
, format:
"{0:d}"
},
45.
UnitPrice: { editable:
true
, type:
"number"
, format:
"{0:c2}"
},
46.
ExtPrice: { editable:
false
, type:
"number"
, format:
"{0:c2}"
},
47.
ProductFK: { editable:
true
},
48.
ProductID: { editable:
true
},
49.
UoM: { editable:
true
},
50.
InvoiceNum: { editable:
true
},
51.
DepFunction: { editable:
true
},
52.
CostCenterFK: { editable:
false
},
53.
AccountFK: { editable:
false
},
54.
OrderFK: { editable:
false
}
55.
}
56.
}
57.
}
58.
});
59.
60.
$(
"#gridLineItems"
).kendoGrid({
61.
dataSource: dataSource,
62.
navigatable:
true
,
63.
pageable:
true
,
64.
toolbar: [{ name:
"create"
, text:
"Insert Line"
}, { name:
"cancel"
}, { name:
"save"
}],
65.
columns: [
66.
{ field:
"LineItemPK"
, title:
"LineItemPK"
, hidden:
true
},
67.
{ field:
"Quantity"
, title:
"Qty"
, validation: { min: 0 } },
68.
{ field:
"UnitPrice"
, title:
"Unit Price"
, validation: { min: 0 } },
69.
{ field:
"ExtPrice"
, title:
"Ext. Price"
, editable:
false
, attributes: {
"class"
:
"ExtPrice"
} },
70.
{ field:
"ProductFK"
, title:
"Product FK"
},
71.
{ field:
"ProductID"
, title:
"Product ID"
},
72.
{ field:
"UoM"
, title:
"UoM"
},
73.
{ field:
"InvoiceNum"
, title:
"Invoice #"
},
74.
{ field:
"DepFunction"
, title:
"Dep. Funct."
},
75.
{ field:
"CostCenterFK"
, title:
"Cost Center"
, hidden:
false
},
76.
{ field:
"AccountFK"
, title:
"G/L"
},
77.
{ field:
"OrderFK"
, title:
"OrderFK"
, editable:
false
, hidden:
true
},
78.
{ command:
"destroy"
, title:
" "
, width: 120 }
79.
],
80.
editable:
true
,
81.
selectable:
true
82.
});
83.
84.
});
So, this is driving me nuts. I've been playing a lot in the parametermap, such as changing the kendo.stringify to a JSON one, because that worked at my last place...doesn't work here. I then did this, in the model, just for kicks...
01.
var
models = {
02.
Quantity: 2,
03.
UnitPrice: 15.00,
04.
ExtPrice: 25.00,
05.
BackOrdered: 0,
06.
Received: 0,
07.
InvoiceNum:
"IT-101"
,
08.
AccountFK: 2,
09.
DepFunction:
"test dep function"
,
10.
CostCenterFK: 34,
11.
ProductFK: 2,
12.
OrderFK: 65,
13.
LineItemPK: 3
14.
};
15.
return
JSON.stringify(models);
And that actually brought that "model" over to the web api end with the correct values, however, hard coded.
In my webapiconfig.cs, my Register method is this.
01.
public
static
void
Register(HttpConfiguration config)
02.
{
03.
// Web API configuration and services
04.
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(
new
MediaTypeHeaderValue(
"text/html"
));
05.
// Web API routes
06.
config.MapHttpAttributeRoutes();
07.
08.
config.Routes.MapHttpRoute(
09.
name:
"DefaultApi"
,
10.
routeTemplate:
"api/{controller}/{id}"
,
11.
defaults:
new
{ id = RouteParameter.Optional }
12.
);
13.
14.
}
On line 4, I did change that to, config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json")); And still, no dice.
I strongly feel it's something on the front end, because when I hard coded that model, the values came over, there's communication - but when I remove it, zilch. I'm hoping someone can help because I've been pulling my hair out on this one. I'm sure it's a matter of me hitting the right combination of stuff.
Thanks in advance.