1

I want to return something like this but it doesn't work:

if (user == null)
{
    return Ok({name: true});
}
return Ok({name: false);

Can someone tell me how I can make it return a value of true of false for a element "name" from my action method.

1
  • 1
    can you not return just a bool? Commented Jul 2, 2015 at 10:06

1 Answer 1

2

If you are using Web API, create a class to have your property Name:

public class NameResponse {
    public bool Name { get; set; }
}

And return the JSON like this:

Request.CreateResponse<NameResponse>(HttpStatusCode.OK, new NameResponse() { Name = true });

If you're not using Web API and using a normal Controller you need to do this:

if (user == null)
{
    return Json(new { name = true });
}
return Json(new { name = false });
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.