How to return a JsonResult or an ActionResult in the same method depending on input?

Viewed 3804

I have a situation where i need return a JSONResult or a Redirect. Is it possible?

Example:

public ActionResult Example(string code)
{
  if(string.IsNullorEmpty(code))
    return RedirectToAction("Index", "Home");
  else
    return Json(new { success = true, message= "Next step"});
}
1 Answers
Related