Fundamentals of MVC
Chapter 1 Fundamentals of MVC
Microsoft's Web Development Platforms
Understanding the past can be a big help in appreciating the present.
1.ASP
asked for features such as improved code reuse,better separation of concerns,and easier application of object-oriented programming principles.
2. ASP.NET Web Forms
an abstraction from the underlying HTML,Js,and Css
3.ASP.NET MVC
The Architecture encourages strict isolation between the individual parts of application.
Benefits:
Development:Isolated componensts;
Testability;
Maintenance.
The MVC Architecture
The model repesents core business logic and data.
The view is responsible for transforming a model or models into a visual representation.
The Controller is the coordinator between the view and the model.
The new in asp.net mvc 4
Async Controllers:just like node.js?
Display modes:different devices.
Bundling and minification:script and css combining and minification.
Web API:supply data to the different platform.
Convention over Config
Action Results
Content() :string
File():file e.g.,a pdf
HttpNotFound() :404
Javascript():js
Json()
PartialView() :without layout
Redirect():302
RedirectPermanent
View()
Action Filters
create own filters by extending the ActionFilterAttribute
Views
Code nuggets
rendered inline. like this: @Html.ActionLink("Login", "Login")
Code blocks
like this:@{}
Layouts
layouts like this:
content like this:
Partial Views
Displaying Data
It is the controller’s job to be the “traffic cop,” coordinating various parts of the system to execute the application’s logic.
ViewData ,
TempData,
ViewBag(dynamic)
View model(Strongly typed).
HTML and URL Helpers
HtmlHelper :helps you generate HTML markup
UrlHelper :helps you generate URLs.
Models
Putting It All Together
As a recap, every ASP.NET MVC request requires at least three things: a route, a controller action, and a view (and, optionally, a model).
The Route
The Summary
ASP.NET MVC leverages the time-tested Model-View-Controller architecture pattern to provide a website development framework that encourages loosely coupled architecture and many other popular object-oriented programming patterns and practices.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?