Asp.net MVC does not use codebehinds, which is true. But. You should not think of your pages as traditional ASP pages, because it is not. Most of the processing (as in the code) is performed inside the controller actions. ASPX pages barely display the results of this processing (when the result of a ViewResult or PartialViewResult ).
Thus, we could say that the controller actions are βcodesβ for many ASPX files.
This, of course, is a very broad simplification of this, but you could understand it that way.
Additional explanation
You may argue that writing C # code in an ASPX file is very similar to writing ASP code, but let me think about it for a moment. In Asp.net WebForms whenever you added
<asp:Repeater ... />
what you basically did was a foreach in a different form with some additional features. In Asp.net MVC, what you write is the actual foreach , and not any additional functionality that you want. In most cases, you will simply create elements without additional functionality, so foreach will be:
- faster than rich server control
- easier since the HTML for each element will be ok. same as repeater element template
- fewer hungry resources, because it is just a simple language construct, and not some kind of server control that needs to be created, executed and saved (as it is able to)
Why can a controller action be the code for many ASPX?
Since we can have code like this
public ActionResult Index() { var data = if (data.Count > 0) { return View("DisplayItems", data); } else { result View("DisplayEmpty"); } }
Not to mention that what this code does is much simpler than complex page lifecycle processing, which would have to handle both states that would lead to a much more complex ASPX file that has all the HTML.
In Asp.net code, MVC is very simple / basic, because it only does what it needs, and views are much simpler, because everyone can serve only one state / situation / purpose. There are no multi-files like in Asp.net WebForms.