首页 > 解决方案 > 迁移到 ASP.NET Core 时出现 JsonRequestBehavior 问题

问题描述

我正在将应用程序从 .NET 4.5 迁移到 Core 3.1,但我遇到了一个奇怪的问题。这就是我的控制器过去的样子

    public ActionResult GetNById(int id)
    {
        var model = cerRepo.GetNById(id);
        return Json(model, JsonRequestBehavior.AllowGet);
    }

    public ActionResult GetAllKO()
    {
        var result = cerRepo.GetAllKO();
        return Json(result, JsonRequestBehavior.AllowGet);
    }
    #endregion


    public ActionResult GetAllUL()
    {
        var result = cerRepo.GetAllUL();
        return Json(result, JsonRequestBehavior.AllowGet);
    }
    #endregion


    public ActionResult GetHN (string str)
    {
        var result = cerRepo.GetHNS (str);
        return Json(result, JsonRequestBehavior.AllowGet);
    }

    public ActionResult GetGrP (string id )
    {
        var result = cerRepo.GetGrP(id);
        return Json(result, JsonRequestBehavior.AllowGet);
    }

}

我正在使用JsonRequestBehavior.AllowGet但我没有在 Core 中使用它,因为它不再使用了,对吗?所以现在我的控制器看起来像这样

public ActionResult GetNById(int id)
    {
        var model = cerRepo.GetNById(id);

        return Json(model);
    }


    public ActionResult GetAllKO()
    {
        var result = cerRepo.GetAllKO();
        return Json(result);
    }

    #region action :: get all street
    public ActionResult GetAllUL()
    {
        var result = cerRepo.GetAllUL();
        return Json(result);
    }

    public ActionResult GetHN(string str)
    {
        var result = cerRepo.GetHNS(str);
        return Json(result);
    }

    public ActionResult GetGrP(string id)
    {
        var result = cerRepo.GetGrP(id);
        return Json(result);
    }

我现在收到一条错误 消息,提示无法加载资源:net::ERR_CONNECTION_REFUSED /Controller/GetALLUL 以及 无法加载资源:net::ERR_CONNECTION_REFUSED /Controller/GetALLKO

我首先在任何地方都使用了 JsonRequestBehavior,但现在我只收到GetALLULGetALLKO的错误

什么可能导致问题?

标签: javascriptc#jsonasp.net-corejson.net

解决方案


推荐阅读