Note that there are some explanatory texts on larger screens.

plurals
  1. POType conversion error with Kendo/Jquery Ajax/Webmethod combo
    primarykey
    data
    text
    <p>I've got a Kendo-UI grid working with WebMethods on the back end. Two of my functions, Read and Create, work perfectly fine. The Create method accepts my object and returns an object of that same type and it all works fine. The problem is the Update method REFUSES to accept THE EXACT SAME THING!</p> <p>Here's my two WebMethods, you can see they are basically the same as far as return types and inputs...</p> <pre><code>[WebMethod()] public static DISP_PROJECT_NAME_MASTER createProject(DISP_PROJECT_NAME_MASTER project) { using (DisputeProjectManagerEntities ctx = new DisputeProjectManagerEntities()) { project.MODIFIED_USER = "user.name"; //TODO: Use Actual Security context ctx.AddToDISP_PROJECT_NAME_MASTER(project); ctx.SaveChanges(); } return project; } [WebMethod()] public static DISP_PROJECT_NAME_MASTER updateProject(DISP_PROJECT_NAME_MASTER project) { DISP_PROJECT_NAME_MASTER pUpdate = null; using (DisputeProjectManagerEntities ctx = new DisputeProjectManagerEntities()) { pUpdate = (DISP_PROJECT_NAME_MASTER)(from p in ctx.DISP_PROJECT_NAME_MASTER where p.PROJECT_ID_NUMBER == project.PROJECT_ID_NUMBER select p).First(); //copy the fields, I guess... pUpdate.ACTIVE = project.ACTIVE; pUpdate.CATEGORY = project.CATEGORY; pUpdate.CONTRIBUTION = project.CONTRIBUTION; pUpdate.DESCRIPTION = project.DESCRIPTION; pUpdate.JUSTIFICATION = project.JUSTIFICATION; pUpdate.MODIFIED_DATE = DateTime.Now; pUpdate.MODIFIED_USER = "user.name"; //TODO: Use Actual Security context pUpdate.PROJECT_NAME = project.PROJECT_NAME; pUpdate.SETTLEMENT = project.SETTLEMENT; pUpdate.WIN_RATE = project.WIN_RATE; ctx.SaveChanges(); } return pUpdate; } </code></pre> <p>And here's my Kendo grid code...</p> <pre><code>$(document).ready(function () { setupGrid(); }); function setupGrid() { var myDataSource = new kendo.data.DataSource({ type: "odata", pageSize: 10, serverPaging: false, serverFiltering: false, serverSorting: false, data: "d", transport: { read: { type: "POST", url: "/special_pages/DisputeProjectManager.aspx/getProjects", contentType: "application/json; charset=utf-8", dataType: "json", data: "{}", success: function (response) { alert('WORKED!'); }, error: function (xhr, textStatus, errorThrown) { handleAjaxError(xhr, textStatus, errorThrown); } }, update: { type: "POST", url: "/special_pages/DisputeProjectManager.aspx/updateProject", contentType: "application/json; charset=utf-8", dataType: "json", data: function (data) { return { project: data }; }, success: function (response) { alert('Project Updated'); }, error: function (xhr, textStatus, errorThrown) { handleAjaxError(xhr, textStatus, errorThrown); } }, create: { type: "POST", url: "/special_pages/DisputeProjectManager.aspx/createProject", contentType: "application/json; charset=utf-8", dataType: "json", data: function (data) { return { project: data }; }, success: function (response) { alert('Project Created'); }, error: function (xhr, textStatus, errorThrown) { handleAjaxError(xhr, textStatus, errorThrown); } }, parameterMap: function (data, type) { return kendo.stringify(data); } }, schema: { data: "d", total: "d.length", model: { id: "PROJECT_ID_NUMBER", fields: { "PROJECT_ID_NUMBER": { type: "number", editable: false }, "PROJECT_NAME": { type: "string", editable: true }, "CATEGORY": { type: "string", editable: true }, "CONTRIBUTION": { type: "string", editable: true }, "WIN_RATE": { type: "string", editable: true }, "SETTLEMENT": { type: "string", editable: true }, "DESCRIPTION": { type: "string", editable: true }, "JUSTIFICATION": { type: "string", editable: true }, "ACTIVE": { type: "string", editable: true }, "MODIFIED_USER": { type: "string", editable: false }, "MODIFIED_DATE": { type: "date", editable: false } } } }, batch: false }); $("#projectManagerGrid").kendoGrid({ dataSource: myDataSource, columns: [{ command: "edit", title: "", width: 110 }, { field: "PROJECT_NAME", title: "Name", width: 200 }, { field: "CATEGORY", title: "Category", width: 150 }, { field: "CONTRIBUTION", title: "Contribution", width: 120 }, { field: "WIN_RATE", title: "Win Rate", width: 90 }, { field: "SETTLEMENT", title: "Settlement", width: 100 }, { field: "DESCRIPTION", title: "Description", width: 300 }, { field: "JUSTIFICATION", title: "Justification", width: 100 }, { field: "ACTIVE", title: "Active Flag", width: 100 }, { field: "MODIFIED_USER", title: "Last Mod User", width: 150 }, { field: "MODIFIED_DATE", title: "Last Mod Date", format: "{0:MMMM dd, yyyy}", width: 150 } ], editable: "inline", toolbar: ["create", "save", "cancel"], pageable: true, sortable: true, resizable: true }); } function handleAjaxError(xhr, textStatus, errorThrown) { alert(errorThrown); } </code></pre> <p>Now, when I call the Create function, it works fine. When I call the Update function, I'm getting the common error (My function never runs, and I get a 500 error with this response): <strong>Can't convert DISP_PROJECT_NAME_MASTER to IDictionary</strong></p> <p>With this stack trace:</p> <pre><code>Cannot convert object of type \u0027DisputeProjectManagerModel.DISP_PROJECT_NAME_MASTER\u0027 to type \u0027System.Collections.Generic.IDictionary`2[System.String,System.Object]\u0027 at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object\u0026 convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object\u0026 convertedObject)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData) ExceptionType:System.InvalidOperationException </code></pre> <p>I can not get rid of that stupid error, even if I change my WebMethod to this...</p> <pre><code>public static void updateProject(object project) { </code></pre> <p>The really maddening thing is, I still get the same error with that method signature, and there's no DISP_PROJECT_NAME_MASTER object involved! Where in heck is it getting that object and why is it trying to convert to IDictionary when there's no reason for that?!</p> <p>With the code above, this is what is posted in the request...</p> <pre><code> { "project": { "__type": "DisputeProjectManagerModel.DISP_PROJECT_NAME_MASTER", "PROJECT_ID_NUMBER": 483, "PROJECT_NAME": "Updated Name", "CATEGORY": "UPDATED Category", "CONTRIBUTION": "N", "WIN_RATE": "N", "SETTLEMENT": "N", "DESCRIPTION": "Desc", "JUSTIFICATION": "Just", "ACTIVE": "N", "MODIFIED_USER": "user.name", "MODIFIED_DATE": "2013-09-03T21:20:13.000Z", "EntityState": 2, "EntityKey": { "EntitySetName": "DISP_PROJECT_NAME_MASTER", "EntityContainerName": "DisputeProjectManagerEntities", "EntityKeyValues": [ { "Key": "PROJECT_ID_NUMBER", "Value": 483 } ], "IsTemporary": false } }, "__type": "DisputeProjectManagerModel.DISP_PROJECT_NAME_MASTER", "PROJECT_ID_NUMBER": 483, "PROJECT_NAME": "Updated Name", "CATEGORY": "UPDATED Category", "CONTRIBUTION": "N", "WIN_RATE": "N", "SETTLEMENT": "N", "DESCRIPTION": "Desc", "JUSTIFICATION": "Just", "ACTIVE": "N", "MODIFIED_USER": "user.nam", "MODIFIED_DATE": "2013-09-03T21:20:13.000Z", "EntityState": 2, "EntityKey": { "EntitySetName": "DISP_PROJECT_NAME_MASTER", "EntityContainerName": "DisputeProjectManagerEntities", "EntityKeyValues": [ { "Key": "PROJECT_ID_NUMBER", "Value": 483 } ], "IsTemporary": false } } </code></pre> <p>Somebody please explain this, I'm not just looking for a code fix, I need to know what's happening here. I've read the entire Encosia site, and 40-50 questions on here, and there's no explanation of how to fix this except stuff that doesn't work. What is going here?</p> <p>A secondary question is why are NONE of my callbacks running? I've never seen an alert pop up when working with this - what good are callbacks if they don't work?</p> <p>I'm very frustrated with this Kendo thing - I'm starting to regret paying actual money for it. I have been working on this for three days, if I had used old-skool data grids I would be done by now.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload