user3172894 user3172894 - 11 days ago 7
ASP.NET (C#) Question

What are the scenarios where we can use Actionresult in MVC?

I know that actionresult is the base class which is inherited by ViewResult,JsonResult etc. but I want to know under what circumstances we can call ActionResult directly.

Answer

When you need to return result based on condition

public ActionResult TestAction()
{
    if(true)
        return View();
    else
        Json(anyObject);
}