I used .NET 7.x (ASP.NET Core 7 MVC) and JavaScript Library v1.10.2 and use XHR in Ajax to get data from the controller as shown here.
Send a request to get data like this:
function SendRequestToGetData() {
var xhr = $.ajax({
url: "/Line/GetData",
type: 'POST',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function (msg) {
// Here I can get the property with this:
var sentdata = msg.Name;
},
error: function (xhr) {}
});
}
On the server side in the controller init an object and return it like this:
public class TestObject
{
public string Name { get; set; }
}
//------------------------------------------------
public class LineController : Controller
{
[HttpPost]
public JsonResult GetData()
{
TestObject testbject=new TestObject {Name="xxxxxxx"};
return Json(testbject);
}
}
It works fine and OK. I updated my project to .NET 8 (.NET Core MVC) and updated JavaScript to Library v3.7.1. Now old codes don't work until the first letter of the property to lowercase so that the codes work correctly.
It means to change this:
var sentdata=msg.Name;
to this:
var sentdata=msg.name; //with the lowercase
Until it works, want to know what and why caused this?