在asp.net web api应用程序中找不到Json类型

Lam*_*fif 1 c# asp.net asp.net-mvc json asp.net-web-api

我的asp.net web api应用程序中有这个控制器:

using AutoMapper;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;  
using Microsoft.Owin.Security;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web;
using System.Web.WebPages.Html;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Net.Mail;


namespace AjTransport.webApi.Controllers 
{
    public class AccountManageController : ApiController
    {

        [AllowAnonymous]
        public System.Web.Mvc.JsonResult FindUser(string str)
        {
            var result = UserManager.FindByName(str) ??   UserManager.FindByEmail(str);
             return Json(result == null, System.Web.Mvc.JsonRequestBehavior.AllowGet);
        }
}
}
Run Code Online (Sandbox Code Playgroud)

问题出在这里

return Json(result == null,System.Web.Mvc.JsonRequestBehavior.AllowGet);

找不到类型Json.所以我需要知道如何解决这个问题?

Igo*_*gor 6

改变这个

return Json(result == null, System.Web.Mvc.JsonRequestBehavior.AllowGet);
Run Code Online (Sandbox Code Playgroud)

return Json(result == null);
Run Code Online (Sandbox Code Playgroud)

也不要退货System.Web.Mvc.JsonResult,改为.

public System.Web.Http.Results.JsonResult<bool> FindUser(string str)
Run Code Online (Sandbox Code Playgroud)

System.Web.Mvc.JsonRequestBehavior.AllowGet仅对MVC有效,而不对WebAPI有效(提示,请参阅您正在使用的类型的名称空间).

有关ApiController.Json方法的更多信息,请参阅链接.