Hi,
I've been having issues binding a custom parameter map to an ASP web api method. I basicly have a kendo grid with a delete button. But by default if I click the delete button it sends the whole data source model for the row as a request. I want it to send just the ID because thats all I need. While its set to the default and I have a viewModel as a input parameter for the web api delete method with the same properties as the data source model everything works fine. I wrote a parameter map that in case of destroy only sends the userID and observed the network request. The ID gets sent fine, but the web API method returns an error that the non nullable input parameter is a null. So it didn't bind right. Anybody had experience with this?
This is the important part of my data source, where you can see the model, parameter map and destroy method, I should note that I also tried using kendo stringify on the return for the parameter map that didnt help.
This is the code for my web Api method, pretty simple:
And I've attached a picture with my http request, the response is: {"Message":"The request is invalid.","MessageDetail":"The parameters dictionary contains a null entry for parameter 'ID' of non-nullable type 'System.Int64' for method 'System.Object Delete(Int64)' in 'Signuper.WebApp.Areas.API.Company.Controllers.TeamMembersController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter."} One final thing to note is that i first named the parameter on the web api method and in the parameter map UserID instead of ID as it is now. When it's like that I get a different webAPI error saying simply that no webAPI method that matches my parameters can be found.
Thanks in advance to anybody that can help!
I've been having issues binding a custom parameter map to an ASP web api method. I basicly have a kendo grid with a delete button. But by default if I click the delete button it sends the whole data source model for the row as a request. I want it to send just the ID because thats all I need. While its set to the default and I have a viewModel as a input parameter for the web api delete method with the same properties as the data source model everything works fine. I wrote a parameter map that in case of destroy only sends the userID and observed the network request. The ID gets sent fine, but the web API method returns an error that the non nullable input parameter is a null. So it didn't bind right. Anybody had experience with this?
This is the important part of my data source, where you can see the model, parameter map and destroy method, I should note that I also tried using kendo stringify on the return for the parameter map that didnt help.
var viewModel = kendo.observable({
teamMembersSource: new kendo.data.DataSource({
transport: {
read: {
url: '@(Url.Action("Get", "TeamMembers", new { Area = "API" }))',
data: {
companyID: '@(((Signuper.WebApp.Infrastructure.SignuperProfessional)User).CompanyID)'
}
},
destroy: {
url: '@(Url.Action("Delete", "TeamMembers", new { Area = "API" }))',
type: "DELETE",
datatype: "json",
},
parameterMap: function (options, type) {
if (type == "destroy") {
return { ID: options.UserID };
}
else
return options;
}
},
schema: {
model: {
id: "UserID",
fields:
{
UserID: { type: "number"},
FirstName: {type: "string"},
LastName: {type: "string"},
Gender: {type:"string"},
CompanyID: { type: "number" },
EmailAdress: { type: "string" },
IsCompanyAdmin: { type: "boolean" },
DateOfBirth: { type: "Date" }
}
},
data: "TeamMembers",
total: "TotalCount"
},
This is the code for my web Api method, pretty simple:
public dynamic Delete(long ID)
{
var user = membership.GetProfessional(ID);
if (user == null)
return new { success = false, errors = "The user that is set to be deleted cannot be found" };
if (ID == ((Signuper.WebApp.Infrastructure.SignuperUser)User).UserID)
return new { success = false, errors = "You cannot delete the currently logged in user" }; // You cant delete your own user
if (((Signuper.WebApp.Infrastructure.SignuperProfessional)User).CompanyID != user.CompanyID)
return new { success = false, errors = "You cannot delete the user of a different company" };
membership.DeleteUser(ID);
return new { success = true, errors = "You cannot delete the user of a different company" };
}
And I've attached a picture with my http request, the response is: {"Message":"The request is invalid.","MessageDetail":"The parameters dictionary contains a null entry for parameter 'ID' of non-nullable type 'System.Int64' for method 'System.Object Delete(Int64)' in 'Signuper.WebApp.Areas.API.Company.Controllers.TeamMembersController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter."} One final thing to note is that i first named the parameter on the web api method and in the parameter map UserID instead of ID as it is now. When it's like that I get a different webAPI error saying simply that no webAPI method that matches my parameters can be found.
Thanks in advance to anybody that can help!