Predefined type 'System.ValueTuple'2' is not defined or imported

1

I'm using asp.net mvc and in my controller, I have the code below:

[HttpGet]
    public JsonResult salvaItem(items item)
    {
        items oItem = new items()
        {
            address = item.address,
            bairro = item.bairro
        };
        return ("ok", JsonRequestBehavior.AllowGet);
    }

In the return line, I'm getting the following error:

  

Predefined type 'System.ValueTuple'2' is not defined or imported

and also

  Can not implicitly convert type '(string, System.Web.Mvc.JsonRequestBehavior AllowGet)' to 'System.Web.Mvc.JsonResult' D: \ OneDrive \ VisualStudio2017 \ siteBuscaFree \ register \ domain \ Controllers \ HomeController.cs 25 Active

    
asked by anonymous 23.12.2017 / 14:29

1 answer

1

The first error occurs for those using the lower version of .NET 4.6.2:

  

Predefined type 'System.ValueTuple'2' is not defined or imported

You need to install the package or change the .NET version 4.6.2 up:

Install-Package "System.ValueTuple"

The second error:

  

Can not implicitly convert type '(string,   System.Web.Mvc.JsonRequestBehavior AllowGet) 'to   'System.Web.Mvc.JsonResult'

You forgot to specify the return type ( Json ) and you should do something like this:

return Json("ok", JsonRequestBehavior.AllowGet);
    
23.12.2017 / 15:04