I use an $.Ajax to call C# API to get data, in the Home controller in Index Action I defined a ViewBag:
public IActionResult Index()
{
ViewBag.UserInfo = "TEST";
return View();
}
Inside the Get API Action:
[HttpGet("Get")]
public IActionResult Get()
{
var x = ViewBag.UserInfo;
return Json(new { result = x});
}
But when I call the API and debug the code, I found that "x" is empty
Please advise