Error: C # The name 'Json' does not exist in the current context

2

I have the following error in C # ' The name' Json 'does not exist in the current context ' in my application. I followed all the steps recommended by various sites, such as adding such references and such, but the error continued.

using System;
using System.Web.Mvc;
using System.IO;
using DevExpress.XtraRichEdit;

namespace PCMSO
{
  public partial class pcmso : System.Web.UI.Page
  {
    [HttpPost]
    public JsonResult SalvaTexto(){
        try
        {
            return Json(new { success = true, message = "Salvo!. "}, JsonRequestBehavior.AllowGet);
        }
        catch (Exception ex)
        {
            return Json(new { success = false, message = "Não foi possível salvar o documento. " + ex.Message }, JsonRequestBehavior.AllowGet);
        }
    }
  }
}
    
asked by anonymous 07.02.2018 / 13:18

1 answer

2
  

Segui todos os passos recomendados por diversos sites, como adicionar tais referências e tal .

Will it?

In your code example, only the following namespaces are included:

using System;
using System.Web.Mvc;
using System.IO;
using DevExpress.XtraRichEdit;

None of them have a type called Json. The first three are authored by Microsoft teams and are well known. The room has documentation here: link

You need to include the namespace that contains the Json type, or call the type by the full name (ie: System.Web.Helpers.Json , though by subscription, does not appear to be the case.)

There is another possibility here, more likely. Maybe you were thinking of the Json method of the Controller class . In this case, for your code to work, the class in which you do your implementation must inherit from System.Web.Mvc.Controller . This is not the case in the code you posted.

    
07.02.2018 / 13:30