I'm having some problems making an ajax call to receive a database object. I am making the ajax call in the View to pass a value from one of the HTML elements in the view to a method in my controller, which uses the value to search for and return an existing data record.
My ajax call:
$.ajax({
url: "/MyController/MyFunction/",
data: {Value: myvalue},
type: 'GET',
success: function (result) {
//do something...
}
My controller method:
Function MyFunction(Value as String) As MyClass
Dim record = SearchFunction(Value)
Return record
End Function
My data class:
Public Class MyClass
Property Name As String
Property Age As Integer
Property DOB As Date
End Class
The Problem I am having is that the 'result' being received in the call returns a string with my model name, i.e. "MyClass", even though the controller is working fine and 'record' is successfully set as the correct data record.
I have tried various different potential solutions after scouring the internet including different dataTypes in the ajax call and different ajax calls like $.getJSON() instead but nothing's worked so far.