2016-02-29 27 views
1

我有這個控制器在我的asp.net網站API應用程序:Json的類型沒有在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); 
     } 
} 
} 

的問題是在這裏

返回JSON(結果= = null,System.Web.Mvc.JsonRequestBehavior.AllowGet);

類型未找到Json。所以我需要知道我該如何解決這個問題?

回答

6

更改此

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

return Json(result == null); 

還沒有返回System.Web.Mvc.JsonResult,修改成。

public System.Web.Http.Results.JsonResult<bool> FindUser(string str) 

System.Web.Mvc.JsonRequestBehavior.AllowGet僅適用於MVC和沒有的WebAPI(提示,查看正在使用類型的命名空間)。

欲瞭解更多關於ApiController.Json方法的信息,請參閱鏈接。

相關問題