-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Description
Description
User feedback transferred from UUF System:
"MVC-based apps contain:Models: Classes that represent the data of the app. The model classes use validation logic to enforce business rules for that data. Typically, model objects retrieve and store model state in a database. In this tutorial, a Movie model retrieves movie data from a database, provides it to the view or updates it. Updated data is written to a database.Views: Views are the components that display the app's user interface (UI). Generally, this UI displays the model data.Controllers: Classes that:Handle browser requests.Retrieve model data. - BUT IT IS SAID ABOVE THAT MODELS RETRIEVE MODEL DATA. Call view templates that return a response."
The following Problem/Solution is just an AI generated recommendation and should be treated as such:
Problem Statement
The introductory explanation in the article "Part 2, add a controller to an ASP.NET Core MVC app" creates a potential confusion regarding the responsibilities of Models and Controllers in MVC. The text states that models "retrieve and store model state in a database" and that "Controllers...retrieve model data." This may give the impression that both are directly responsible for data retrieval, rather than emphasizing that controllers orchestrate the request and invoke model logic, while models encapsulate the data and its operations. This ambiguity can cause confusion for new learners trying to understand the separation of concerns in MVC.
Proposed Solution
Clarify and distinguish the roles of models and controllers:
- Specify that controllers handle browser requests and invoke model methods to retrieve or modify data.
- State that models encapsulate data and business logic, but data retrieval typically occurs through methods called by controllers, not directly by user interaction.
- Make the separation of responsibilities explicit in the introductory explanation.
Suggested Changes
Location: aspnetcore/tutorials/first-mvc-app/adding-controller.md, around lines describing Models and Controllers in the "MVC-based apps contain:" section (approx. lines 17-26)
Suggested revision:
Replace:
* **M**odels: Classes that represent the data of the app. The model classes use validation logic to enforce business rules for that data. Typically, model objects retrieve and store model state in a database.
With:
* **M**odels: Classes that represent the data and business logic of the app. Model classes may provide methods to retrieve or update data, typically interacting with a database. Data retrieval is usually performed by methods that are invoked by controllers in response to user requests.
And clarify the controller section:
* **C**ontrollers: Classes that:
* Handle browser requests.
* Invoke model methods to retrieve or modify data.
* Call view templates that return a response.
This makes it clear that controllers orchestrate the data access via models, rather than implying that both are responsible for data retrieval independently.
If you need code examples, consider updating the comments in the HelloWorldController.cs sample to clarify the relationship:
// Controller action method calls model methods to retrieve or update data as needed
public IActionResult Index() {
var movies = MovieModel.GetAll(); // Example: controller invokes model logic
return View(movies);
}Page URL
Content source URL
Document ID
3477519b-1bc2-73be-33e3-63067383d426
Platform Id
b8a33c0b-62ed-b8bf-9525-c25c677e0645
Article author
Metadata
- ID: 20264150-9ac7-2b21-3314-64ffa114410f
- PlatformId: b8a33c0b-62ed-b8bf-9525-c25c677e0645
- Service: aspnet-core
- Sub-service: tutorials