Reputation: 9081
I have this controller in my asp.net web api application :
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);
}
}
}
The problem is here
return Json(result == null, System.Web.Mvc.JsonRequestBehavior.AllowGet);
the type Json is not found. So I need to know how can I fix this?
Upvotes: 1
Views: 2136
Reputation: 62318
Change this
return Json(result == null, System.Web.Mvc.JsonRequestBehavior.AllowGet);
to
return Json(result == null);
Also do not return a System.Web.Mvc.JsonResult
, change that to.
public System.Web.Http.Results.JsonResult<bool> FindUser(string str)
This System.Web.Mvc.JsonRequestBehavior.AllowGet
is only valid for MVC and not WebAPI (hint, see the name space of the type you are using).
For more info on ApiController.Json method see the link.
Upvotes: 7