tags:

views:

123

answers:

2

Is there a mandatory relationship between a Controller Action and a View? I mean is it necessary to have a physical View (.aspx page) for each Action inside a Controller class?

+3  A: 

There is no mandatory relationship between the Controller Action and a view. The controller is responsible for returning an ActionResult. The most usual way of doing this is by using a View, but they aren't hard wired. A view could be shared across Controllers for instance.

Also a Controller, can deal with the request purely on its own, returning a redirect, or a JSON result, or even its own html (though not recommended).

Andrew Rimmer
In an ActionResult, if I wanna return View(), I should have a View (.aspx) right? in other return types (RedirectToAction, etc.) there is no need to have a View, Right?!
Mahdi
+2  A: 

You can also return things like ContentResult in an action:

public ContentResult Index()
{
 return Content("Foobar!");
}

If this was called directly, this would be similar to:

Response.Write("Foobar!");
Response.End();
Dan Atkinson