We are facing an issue while upgrading Infragistics.MVC.dll 2017 to 2022 version.
It looks like in the new version (2022), the content type should be “application/JSON” for all the AJAX POST requests (and obviously the data should be in a proper JSON format). But in our project, there are places where we make the AJAX POST with content type as “application/x-www-form-urlencoded” (data sent in the HTTP message body) and ended up getting the following error while using v2022 DLL - “unexpected character encountered while parsing value path line” while deserializing the input.
We haven’t faced this issue in v2017 DLL. So, I tried to compare the 2 DLLs and found that, there is a new condition specifically for POST requests to handle JSON content and that is what is causing this issue in v2022.
Is this something we have to change in our scripts to use “application/JSON” for all AJAX POST calls (or) is there another way to support form postings back to an IG method?
Hello,
Thank you for the provided sample and additional information.
After further investigation I determined that this is the expected behavior of the grid, which was added as you specified in the given code from version 2018.2, and after the design changes, the GridDataSourceAction method accepts post requests only under json so that the given data can be bound to the grid.
What I propose as an approach is according to your custom logic and based on how the given application is built to check before making post requests to the controller action method whether the data is in the form of "application/x-www-form-urlencoded" that is query string or in the form of "application/json", that is, json. Based on this, you can transform all query string requests with a given function to json and only perform post requests to the controller action method of type json so that you do not experience the described behavior. You can implement different types of functions according to your custom logic to convert the query string of type "application/x-www-form-urlencoded" to the json data of type "application/json" and according to what exactly the query string is in your application. There are also many other options that you can look at as suggested in stack overflow and other articles and forums by doing your research.
However, I went through your sample in detail and made a sample function that converts the query string of type "application/x-www-form-urlencoded" to json of type "application/json" by taking the given string and splitting it first with the “&” character then the compiled array after splitting the string is looped and each pair of key and value is concatenated by the “=” character. In a given variable key and value are added and separated by a comma from the next pair then finally the JSON.stringify method is used to concatenate to json and the result is returned. The POST ajax request takes the query string and passes it to this function which converts it and makes a request of type json to the controller action method successfully.
function queryStringToJSON(qs) { var input = qs.split('&'); var result = {}; input.forEach(function (p) { var pair = p.split('='); var key = pair[0]; var value = decodeURIComponent(pair[1] || ''); if (result[key]) { if (Object.prototype.toString.call(result[key]) === '[object Array]') { result[key].push(value); } else { result[key] = [result[key], value]; } } else { result[key] = value; } }); return JSON.stringify(result); };
The described scenario could be observed here:
I have prepared small sample illustrating my suggestion which could be found attached here. Please test it on your side and let me know how it behaves.
7522.igGridQueryStringToJson.zip
Additional information on some of the different options for convening the two types can be found in this stackoverflow article and this next article. More information about both types can be found here.
Thank you for your cooperation.
Regards,
Georgi Anastasov
Entry Level Software Developer
Infragistics
I couldn't upload the file as it was too big. See if you can access this link:
https://cedinc.box.com/s/hr2ecxejwzxyrzgtguj5adh4cd9nbt69
This sample has 2 buttons –
Basically, if the request content type is other than JSON, we are getting parse error while posting data to the controller. Hope this helps.
FYI – Refer Home/index.cshml for the sample
Thank you for the provided information, for the screenshot and for the details about described behavior.
However, in order to ensure that the described scenario is addressed correctly, I will need some additional information regarding your scenario. Could you please answer the following questions:
This information is going to be highly appreciated and will help me in my further investigation determining whether the described behavior will be determined as an issue of the given control that must provide post requests of any type or the given control provides only json type request processing and may require subsequent modification of your custom request execution logic only from json type.
Having a working sample on my side, which I can debug, is going to be very helpful in finding the root cause of this behavior.