0

On an ASP.NET Core application I have the following action:

public async Task<IActionResult> Get() {

  Reply reply = service.GetData();  

  return reply.Errors.Count > 0 ? HttpBadRequest(reply) : Ok(reply);

}

I get an error because HttpBadRequest and Ok are not of the same type.

I know I can use an IF but is there a way to create the response in a different way?

1 Answer 1

1

You can cast both of them as an IActionResult as implied by your response.

public async Task<IActionResult> Get()
{

    Reply reply = service.GetData(); 

    return reply.Errors.Count > 0 ? (IActionResult)HttpBadRequest(reply) : Ok(reply);

}
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.