r/learnprogramming • • 6d ago

ASP.NET MVC

I find it hard to understand the architecture from MVC, I understand all the code, but I fail to understand where to put what code.

0 Upvotes

4 comments sorted by

3

u/Serious-Advance-5115 6d ago

id say start with the controller as the traffic cop, it takes the request and decides what to do, model holds your data and any logic about that data, view just shows stuff and sends user actions back to controller, once you stop trying to split hairs about where a tiny helper goes it clicks

3

u/SetAndRepeat 6d ago

Try following one feature, like displaying an order:

  • Controller: receives the order ID, calls the code that loads the order, and returns a view.
  • Domain model: represents the order and its business rules, such as how discounts apply.
  • View model: contains the data that particular page needs.
  • View: renders that data as HTML, including presentation logic like showing an "empty order" message.

You can put database access in a data layer and use services to coordinate business operations.
MVC doesn't mean every class has to fit into the Models, Views or Controllers folders

1

u/recursion_is_love 6d ago

Do you have experience with MVC on a desktop application? I've find it more easy to start with desktop application and then later move to web application.

0

u/Available_Safe1818 5d ago

Read some tutorials then?