Reputation: 197
I am developing a page that shows the webgrid of all values of Leave Type Option (which is a model containing id, LeaveType and status). In my controller, I have written something below.
After I run the code, I got the runtime error
InvalidOperationException: Property 'JsonResult.SerializerSettings' must be an instance of type 'System.Text.Json.JsonSerializerOptions'
I tried to google it but I don't understand this issue and I would like to seek advice on how to solve this.
Thank you.
public class OptLeaveTypeController : Controller
{
private readonly theManagerContext _context;
public OptLeaveTypeController(theManagerContext context)
{
_context = context;
}
public IActionResult Index()
{
return View();
}
public IActionResult GetLeaveTypes()
{
var leaveTypes = _context.OptLeaveType.OrderBy(a => a.LeaveTypeId).ToList();
return Json(new { data = leaveTypes }, System.Web.Mvc.JsonRequestBehavior.AllowGet);
}
}
Upvotes: 11
Views: 18305
Reputation: 5284
1) .NET CORE MVC:-
public IActionResult GetLeaveTypes()
{
var leaveTypes = _context.OptLeaveType.OrderBy(a => a.LeaveTypeId).ToList();
return Json(new { data = leaveTypes });
}
OR
public IActionResult GetLeaveTypes()
{
var leaveTypes = _context.OptLeaveType.OrderBy(a => a.LeaveTypeId).ToList();
return new JsonResult(new { data = leaveTypes });
}
2) .NET MVC:-
public ActionResult GetLeaveTypes()
{
var leaveTypes = _context.OptLeaveType.OrderBy(a => a.LeaveTypeId).ToList();
return Json(new { data = leaveTypes }, System.Web.Mvc.JsonRequestBehavior.AllowGet);
}
Upvotes: 8