MVC Summary - Day 1
MVC Summary - Day 1
Models are responsible for data access and business rules. Views are
responsible for presenting the user interface, such as HTML pages or JSON
responses. Controllers are responsible for handling user requests, working
with the models, and selecting the views
Class Library:
Round Trip:
1. Case Insensitivity:
HTTP response is case insensitive, which means that the names of the
headers and the values of some fields (such as methods and status codes)
are not affected by the letter case.
For example, Content-Type: text/html and content-type: TEXT/HTML are
equivalent.
2. Statelessness:
HTTP is stateless. This means that each request-response cycle is
independent and the server doesn't remember previous interactions with
the same client.
To maintain state information across requests, we need additional
mechanisms like:
Session Management: Stores user data on the server for a specific
duration.
Cookies: Stores small data pieces on the client's browser, accessible by
the server.
Hidden fields: Embed data in forms submitted to the server.
3. Connectionless:
HTTP connections are connectionless. This means that after a response is
sent, the connection is closed.
For subsequent requests, a new connection is established.
This is efficient for short-lived interactions, but persistent connections
(e.g., WebSockets) exist for longer-lasting communication.
This reduces the overhead of keeping the connection alive and allows the
server to handle more requests. However, this also increases the latency
and the network traffic for each request.
Status Codes:
Status code is a 3-digit number that indicates the result of the HTTP request.
The first digit defines the class of the response, and the last two digits are
specific to each status.
100 Information: Indicate that the request was received and the
processing is continuing. For example, 100 Continue means that the client
should continue the request or ignore the response if the request is
already finished.
500 Server Error: Indicate that the server failed to fulfill a valid request.
For example, 500 Internal Server Error means that the server encountered
an unexpected condition that prevented it from completing the request.
Model:
Represents data and business logic, often mapped to database entities. The
Model includes validation rules and view models for data presentation.
View:
Responsible for presenting data to the user. A View uses Razor syntax, a
combination of HTML and C#, to dynamically generate HTML content.
Different views exist for various actions (create, edit, show) within an entity.
The Razor engine converts views to HTML understandable by the browser.
Controller:
The "brain" of the application, handling user requests. The Controller receives
requests from the web server, interacts with the Model for data, and chooses
the appropriate View. It consists of C# classes with methods for different
actions.