Im calling an ajax function in a modal when I press a BTN which calls a Controller action and passes a parameter to controller. I now want to return strings as a Json back to the view and display them in the same Modal. Weirdly it worked on my laptop with dependency "System.Web.MVC" but doesnt seem to work in "Microsoft.AspNetCore.Mvc". When returning the Jsons I fill the inputs in the modal with those json strings but on the PC with asp.net core the Inputs just stay empty where on the laptop they get filled.
Controller return type
return Json(new { Nachname, Vorname, UserName });
Ajax
$(document).ready(function () {
$("#btnGet").click(function () {
$.ajax(
{
type: "POST",
url: "@Url.Action("getName", "Home")",
data: {
UserName: $("#txtName").val()
},
success: function (result) {
$('#infos').show();
$('#txtName').addClass("form-control is-valid");
$('#InputFirstName').val(result.Vorname);
$('#InputLastName').val(result.Nachname);
$('#InputFirstName').show();
$('#InputLastName').show();
$('#labelInfo').show();
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
});
});
`
console.log(result);what's displayed in the console?return new JsonResult(new { Nachname, Vorname, UserName });, becauseControllerBasedoesn't haveJsonmethod.