I am looking for a way to transfer various types of data from JavaScript to C#. Specifically, I want to send a JSON object from the JavaScript side using an AJAX call. Here is an example:
AnObject = new Object;
AnObject.value = anyValue;
$.ajax({
type: "POST",
url: "myURL",
data: "{ 'myObject':" + JSON.stringify(AnObject) + "}",
dataType: 'json',
success: function (data) {
//perform actions here
}
});
The value of `anyValue` could be an integer, string, array, associative array, date, etc.
On the C# side, I need a class similar to this:
public AnyClass {
DataType(?) value;
}
public ActionResult acceptData(AnyClass myObject) {
In this method, the incoming data should be deserialized correctly based on its type into `DataType(?)`.
}
Is it feasible to achieve this? I believe there might be a generic type in C# that can help with this process?