1

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?

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.