Bubinga
Bubinga

Reputation: 703

Cannot implicitly convert type 'bool' to 'Microsoft.AspNetCore.Mvc.ActionResult'

I am attempting to return a true/false value to a page with an ajax request, but I am getting an error of:

Cannot implicitly convert type 'bool' to 'Microsoft.AspNetCore.Mvc.ActionResult' Here is my code:

public ActionResult CheckSignedIn()
{
    return _signInManager.IsSignedIn(User);
}   

I am rather new to programming, and thus I'm not sure what to change ActionResult out for, nor what ActionResult even means. Any solution or explanation would be appreciated

Upvotes: 2

Views: 3453

Answers (1)

Prasad Telkikar
Prasad Telkikar

Reputation: 16079

From MSDN documentation:

The ActionResult types represent various HTTP status codes. Any non-abstract class deriving from ActionResult qualifies as a valid return type

In your case, API expecting to return HTTP status code, not a boolean value, so return status code with your boolean value

public ActionResult CheckSignedIn()
{
    return Ok(_signInManager.IsSignedIn(User));
}

Upvotes: 3

Related Questions