Geo*_*rge 8 c# asp.net-mvc json asp.net-core-mvc .net-core
我正在开发一个页面,显示休假类型选项的所有值的网络网格(这是一个包含 id、LeaveType 和状态的模型)。在我的控制器中,我写了下面的内容。
运行代码后,出现运行时错误
InvalidOperationException:属性“JsonResult.SerializerSettings”必须是类型“System.Text.Json.JsonSerializerOptions”的实例
我尝试用谷歌搜索,但我不明白这个问题,我想寻求有关如何解决这个问题的建议。
谢谢。
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);
}
}
Run Code Online (Sandbox Code Playgroud)
1).NET核心MVC:-
public IActionResult GetLeaveTypes()
{
var leaveTypes = _context.OptLeaveType.OrderBy(a => a.LeaveTypeId).ToList();
return Json(new { data = leaveTypes });
}
Run Code Online (Sandbox Code Playgroud)
或者
public IActionResult GetLeaveTypes()
{
var leaveTypes = _context.OptLeaveType.OrderBy(a => a.LeaveTypeId).ToList();
return new JsonResult(new { data = leaveTypes });
}
Run Code Online (Sandbox Code Playgroud)
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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15973 次 |
| 最近记录: |