Say I have a controller action like so:
public ActionResult Foo() {
return View(new SomeModel {...});
}
Is it possible for me to, at runtime, have this action return JSON instead of HTML? This is for some automated testing. The only way I have found would be to modify my controller's base class to override View(...)
such that they if some setting is true, it returns Json(model)
instead of what it normally does.
I'd rather not do that as it would mean a conditional which gets evaluated for every action even in non-test environments.