Predefined type 'System.Valuetuple 2 is not defined or Imported

Asked

Viewed 99 times

1

I am 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);
    }

on the Return line, I’m getting the following error:

Predefined type 'System.Valuetuple 2 is not defined or Imported

and also

Cannot implicitly Convert type '(string, System.Web.Mvc.Jsonrequestbehavior Allowget)' to 'System.Web.Mvc.Jsonresult' registration D: Onedrive Visualstudio2017 siteBuscaFree registration Controllers Homecontroller.Cs 25 Active

1 answer

1


The first error happens to those who use 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 version . NET 4.6.2 up:

Install-Package "System.ValueTuple"

The second mistake:

Cannot implicitly Convert type '(string, System.Web.Mvc.Jsonrequestbehavior Allowget)' to 'System.Web.Mvc.Jsonresult'

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

return Json("ok", JsonRequestBehavior.AllowGet);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.