Why would you want to do that? For me, the controller is tied to a specific model, and not to a specific type of output format.
public ActionResult Users()
{
var users = _repository.Find();
var viewModel = Mapper.Map(users);
return Request.IsAjax() ? Json(viewModel) : View(viewModel);
}
To respond to your update
It is better to create CustomAuthorizeAttributeone that checks if it is an ajax request or a regular request and does the correct authorization. Your controllers do not need to know how authorization is done.
source
share