Asp.net,mvc

Prashant Kumar
Prashant KumarAssociate Software Engineer at Alligator Software em Alligator Software India
ASP.NET and
Model View Control
Jesper Tørresø
ITNET2
F08
Turns around the usual way
• A MVC Controller takes control over from the standard
ASP.NET Framework View Engine.
• From Scott Guthrie
– ”The MVC framework supports using the existing
ASP.NET .ASPX, .ASCX, and .Master markup files as "view
templates" (meaning you can easily use existing ASP.NET
features like nested master pages, <%= %> snippets,
declarative server controls, templates, data-binding,
localization, etc). It does not, however, use the existing
post-back model for interactions back to the server.
Instead, you'll route all end-user interactions to a Controller
class instead - which helps ensure clean separation of
concerns and testability (it also means no viewstate
or page lifecycle with MVC based views). ”
But what about the existing
ASP.NET framework?
• May we ”only” use HTML control and not
server controls and/oe user controls?
• All HTML from controls may be used
• We can use the already known APS.NET
server controls and also a special MVC
User Control. (!!!!)
• But we must take care of routing etc by
our self.
Model View Control
JSP Model 1 architecture (from 1998-1999)
Is this original ASP.NET ?
Model View Control
JSP Model 2 architecture
Model, View and Controller:
The pattern MVC, which stands for Model-View-Controller, separates
an application in three components:
• Model: this is where all the business logic of the application resides:
it can range from a simple static class that returns a dataset to a
complex multi-assembly Business Logic Layer that uses an
assembly specific to the Data Access Layer.
• View: at the other end of the application is the View, which displays
the application's user interface and contains the representation of
the data that have been retrieved by the Model. This doesn't have
logic, other than the one strictly related to the presentation of data.
• Controller: between the two components stands the Controller. It
acts as the orchestrator of all the interactions among the other
components and the users: it handles the requests, reads the form
values, passes them to the Model, decides which View to render
and finally sends the data to be rendered to the View.
Interaction
1. The request comes from the client
and hits the Controller.
2. The Controller calls the Model in
order to perform some "business"
operations.
3. The Model returns the results of the
operations back to the Controller.
4. The Controller decides which View
needs to be rendered and sends it
the data that must be rendered.
5. Finally the View renders the output
and sends the response back to the
client.
Model 2 and ASP.NET
URL Routning
• Normal ASP.NET
– http://server/application/Products.aspx?id=4
• ASP.NET MVC
– http://server/application/Products/show/beverages
• The URL’s are interpreted by a
RouteHandler and known as routes to the
Controller.
URL Routning 1
• The URL patterns defined are called
routes Ex:
Valid route definitions Examples of matching URL
{controller}/{action}/{id} /Products/show/beverages
{table}/Details.aspx /Products/Details.aspx
blog/{action}/{entry} /blog/show/123
{reporttype}/{year}/{month}/{day} /sales/2008/1/5
Typically, you add routes in the handler for the
Application_Start event in the Global.asax file. This approach
makes sure that the routes are available when the application
starts.
URL Routning 2
• Initiating application in Global.asax.cs
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.Add(new Route ( "Category/{action}/{categoryName}"
new CategoryRouteHandler() )
{
Defaults = new RouteValueDictionary
{{"categoryName", "food"}, {"action", "show"}}
}
);
}
URL Routning 3
• See more here
– http://quickstarts.asp.net/3-5-extensions/mvc/URLR
• Setting default values in Routes
• Adding constraints Routes
• Making a MVC route to a URL
Sow! What is ASP.NET MVC?
• ASP.NET MVC is a framework that allows developers to apply the
MVC pattern in the development of an ASP.NET application, thus
allowing a better separation of concerns, which results in better
reusability and easier testing.
• MVC was one of the concepts originally found in SmallTalk. MVC
and the web seem like a match made in heaven and allow for a
simple way of building complex web applications.
• To understand why this recently re-discovered way of building web
application was developed, we need to have a look at the pitfalls of
the standard model, which is the web-form approach.
– First, it is event based: it can be good or bad depending on how you
look at it. Good because it helps VB6 and WinForms developers to
smoothly migrate their skills to the web application development. Bad
because there are dozens of events that are raised during the page life-
cycle, and it's not trivial to understand where to put your code. Also
because the process logic is tightly coupled with the page life-
cycle, it is difficult to test using automated tests. Cont..
Sow! What is ASP.NET MVC?
cont.
– It also uses server forms and ViewState: again, as with the event based
model, it can be good since this hides to the developer all the problems related
to maintaining the state of the page (values of textboxes, contents of dropdowns
and so on), but can also be bad if you want to control exactly how the page is
rendered, and you don't need to maintain all the state.
– Furthermore, it uses server controls: good because they render the HTML for
you; bad since they render it the way they want.
• With the MVC framework you gain back the control of the order in which
things happen during the page life-cycle, of the way state is persisted
between requests, and the code with which HTML is rendered. And thanks
to a better separation of concerns it's easier to test the process logic. But
all this control has a cost: you have to do everything by yourself.
• Keep in mind this: the MVC framework is not a replacement for the web-
form programming model, but it's an alternative programming model, for
those who want to have a better control and want to be able to also test the
presentation logic
1 de 14

Recomendados

Asp.net With mvc handson por
Asp.net With mvc handsonAsp.net With mvc handson
Asp.net With mvc handsonPrashant Kumar
454 visualizações64 slides
Word press 01 por
Word press 01Word press 01
Word press 01AbhishekMondal42
25 visualizações7 slides
ASP .NET MVC por
ASP .NET MVC ASP .NET MVC
ASP .NET MVC eldorina
1K visualizações13 slides
Dot net interview questions and asnwers por
Dot net interview questions and asnwersDot net interview questions and asnwers
Dot net interview questions and asnwerskavinilavuG
99 visualizações17 slides
Asp.net mvc presentation by Nitin Sawant por
Asp.net mvc presentation by Nitin SawantAsp.net mvc presentation by Nitin Sawant
Asp.net mvc presentation by Nitin SawantNitin Sawant
2.3K visualizações27 slides
Asp 1a-aspnetmvc por
Asp 1a-aspnetmvcAsp 1a-aspnetmvc
Asp 1a-aspnetmvcFajar Baskoro
19 visualizações22 slides

Mais conteúdo relacionado

Mais procurados

Asp.net mvc basic introduction por
Asp.net mvc basic introductionAsp.net mvc basic introduction
Asp.net mvc basic introductionBhagath Gopinath
294 visualizações10 slides
Mvc framework por
Mvc frameworkMvc framework
Mvc frameworkDhurham Fahem
128 visualizações10 slides
Asp.net MVC training session por
Asp.net MVC training sessionAsp.net MVC training session
Asp.net MVC training sessionHrichi Mohamed
6.3K visualizações44 slides
MVC Architecture in ASP.Net By Nyros Developer por
MVC Architecture in ASP.Net By Nyros DeveloperMVC Architecture in ASP.Net By Nyros Developer
MVC Architecture in ASP.Net By Nyros DeveloperNyros Technologies
4.3K visualizações24 slides
Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing por
Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazingMortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing
Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazingTom Walker
690 visualizações13 slides
Introduction to mvc architecture por
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architectureravindraquicsolv
1.3K visualizações17 slides

Mais procurados(20)

Asp.net mvc basic introduction por Bhagath Gopinath
Asp.net mvc basic introductionAsp.net mvc basic introduction
Asp.net mvc basic introduction
Bhagath Gopinath294 visualizações
Mvc framework por Dhurham Fahem
Mvc frameworkMvc framework
Mvc framework
Dhurham Fahem128 visualizações
Asp.net MVC training session por Hrichi Mohamed
Asp.net MVC training sessionAsp.net MVC training session
Asp.net MVC training session
Hrichi Mohamed6.3K visualizações
MVC Architecture in ASP.Net By Nyros Developer por Nyros Technologies
MVC Architecture in ASP.Net By Nyros DeveloperMVC Architecture in ASP.Net By Nyros Developer
MVC Architecture in ASP.Net By Nyros Developer
Nyros Technologies4.3K visualizações
Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing por Tom Walker
Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazingMortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing
Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing
Tom Walker690 visualizações
Introduction to mvc architecture por ravindraquicsolv
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
ravindraquicsolv1.3K visualizações
Introduction to ASP.NET MVC por Emad Alashi
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
Emad Alashi925 visualizações
"Umbraco MVC - a journey of discovery" - Lotte Pitcher por lottepitcher
"Umbraco MVC - a journey of discovery" - Lotte Pitcher"Umbraco MVC - a journey of discovery" - Lotte Pitcher
"Umbraco MVC - a journey of discovery" - Lotte Pitcher
lottepitcher9.4K visualizações
Using MVC with Kentico 8 por Thomas Robbins
Using MVC with Kentico 8Using MVC with Kentico 8
Using MVC with Kentico 8
Thomas Robbins4.2K visualizações
Asp.net mvc por Naga Harish M
Asp.net mvcAsp.net mvc
Asp.net mvc
Naga Harish M1.9K visualizações
ASP.NET MVC Presentation por ivpol
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
ivpol23.6K visualizações
MSDN - ASP.NET MVC por Maarten Balliauw
MSDN - ASP.NET MVCMSDN - ASP.NET MVC
MSDN - ASP.NET MVC
Maarten Balliauw6K visualizações
ASP.NET MVC Performance por rudib
ASP.NET MVC PerformanceASP.NET MVC Performance
ASP.NET MVC Performance
rudib59.7K visualizações
MVC ppt presentation por Bhavin Shah
MVC ppt presentationMVC ppt presentation
MVC ppt presentation
Bhavin Shah14K visualizações
Active Server Page(ASP) por Keshab Nath
Active Server Page(ASP)Active Server Page(ASP)
Active Server Page(ASP)
Keshab Nath31.5K visualizações
New Features of ASP.NET 4.0 por Buu Nguyen
New Features of ASP.NET 4.0New Features of ASP.NET 4.0
New Features of ASP.NET 4.0
Buu Nguyen7.9K visualizações
ASP.NET MVC Presentation por Volkan Uzun
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
Volkan Uzun5.4K visualizações
Mvc summary por Muhammad Younis
Mvc summaryMvc summary
Mvc summary
Muhammad Younis2.4K visualizações
Architecting ASP.NET MVC Applications por Gunnar Peipman
Architecting ASP.NET MVC ApplicationsArchitecting ASP.NET MVC Applications
Architecting ASP.NET MVC Applications
Gunnar Peipman5.7K visualizações

Similar a Asp.net,mvc

MVC Framework por
MVC FrameworkMVC Framework
MVC FrameworkAshton Feller
1.4K visualizações27 slides
Mvc por
MvcMvc
MvcFurqan Ashraf
844 visualizações51 slides
MVC 4 por
MVC 4MVC 4
MVC 4Vasilios Kuznos
354 visualizações266 slides
Introduction To Mvc por
Introduction To MvcIntroduction To Mvc
Introduction To MvcVolkan Uzun
2.4K visualizações28 slides
Technoligent providing custom ASP.NET MVC development services por
Technoligent providing custom ASP.NET MVC development servicesTechnoligent providing custom ASP.NET MVC development services
Technoligent providing custom ASP.NET MVC development servicesAaron Jacobson
878 visualizações16 slides
Mvc Brief Overview por
Mvc Brief OverviewMvc Brief Overview
Mvc Brief Overviewrainynovember12
1.3K visualizações9 slides

Similar a Asp.net,mvc(20)

MVC Framework por Ashton Feller
MVC FrameworkMVC Framework
MVC Framework
Ashton Feller1.4K visualizações
Mvc por Furqan Ashraf
MvcMvc
Mvc
Furqan Ashraf844 visualizações
MVC 4 por Vasilios Kuznos
MVC 4MVC 4
MVC 4
Vasilios Kuznos354 visualizações
Introduction To Mvc por Volkan Uzun
Introduction To MvcIntroduction To Mvc
Introduction To Mvc
Volkan Uzun2.4K visualizações
Technoligent providing custom ASP.NET MVC development services por Aaron Jacobson
Technoligent providing custom ASP.NET MVC development servicesTechnoligent providing custom ASP.NET MVC development services
Technoligent providing custom ASP.NET MVC development services
Aaron Jacobson878 visualizações
Mvc Brief Overview por rainynovember12
Mvc Brief OverviewMvc Brief Overview
Mvc Brief Overview
rainynovember121.3K visualizações
Aspnetmvc 1 por Fajar Baskoro
Aspnetmvc 1Aspnetmvc 1
Aspnetmvc 1
Fajar Baskoro2K visualizações
MVC por Ravi Bansal
MVCMVC
MVC
Ravi Bansal755 visualizações
Asp 1-mvc introduction por Fajar Baskoro
Asp 1-mvc introductionAsp 1-mvc introduction
Asp 1-mvc introduction
Fajar Baskoro2.1K visualizações
Getting started with MVC 5 and Visual Studio 2013 por Thomas Robbins
Getting started with MVC 5 and Visual Studio 2013Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013
Thomas Robbins14.9K visualizações
Session 1 por Asif Atick
Session 1Session 1
Session 1
Asif Atick521 visualizações
ASP.Net MVC 4 [Part - 2] por Mohamed Abdeen
ASP.Net MVC 4 [Part - 2]ASP.Net MVC 4 [Part - 2]
ASP.Net MVC 4 [Part - 2]
Mohamed Abdeen3.3K visualizações
Architectural Design & Patterns por Inocentshuja Ahmad
Architectural Design&PatternsArchitectural Design&Patterns
Architectural Design & Patterns
Inocentshuja Ahmad679 visualizações
Jinal desai .net por rohitkumar1987in
Jinal desai .netJinal desai .net
Jinal desai .net
rohitkumar1987in321 visualizações
Introduction to Angularjs : kishan kumar por Appfinz Technologies
Introduction to Angularjs : kishan kumarIntroduction to Angularjs : kishan kumar
Introduction to Angularjs : kishan kumar
Appfinz Technologies 19 visualizações
Introduction to Angularjs por Manish Shekhawat
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
Manish Shekhawat67.3K visualizações
Asp.net mvc por Taranjeet Singh
Asp.net mvcAsp.net mvc
Asp.net mvc
Taranjeet Singh248 visualizações
IRJET- MVC Framework: A Modern Web Application Development Approach and Working por IRJET Journal
IRJET- MVC Framework: A Modern Web Application Development Approach and WorkingIRJET- MVC Framework: A Modern Web Application Development Approach and Working
IRJET- MVC Framework: A Modern Web Application Development Approach and Working
IRJET Journal12 visualizações
Asp.net c# MVC-5 Training-Day-1 of Day-9 por AHM Pervej Kabir
Asp.net c# MVC-5 Training-Day-1 of Day-9Asp.net c# MVC-5 Training-Day-1 of Day-9
Asp.net c# MVC-5 Training-Day-1 of Day-9
AHM Pervej Kabir923 visualizações

Último

Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu... por
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...NUS-ISS
32 visualizações54 slides
"Role of a CTO in software outsourcing company", Yuriy Nakonechnyy por
"Role of a CTO in software outsourcing company", Yuriy Nakonechnyy"Role of a CTO in software outsourcing company", Yuriy Nakonechnyy
"Role of a CTO in software outsourcing company", Yuriy NakonechnyyFwdays
40 visualizações21 slides
Future of Learning - Khoong Chan Meng por
Future of Learning - Khoong Chan MengFuture of Learning - Khoong Chan Meng
Future of Learning - Khoong Chan MengNUS-ISS
31 visualizações7 slides
Future of Learning - Yap Aye Wee.pdf por
Future of Learning - Yap Aye Wee.pdfFuture of Learning - Yap Aye Wee.pdf
Future of Learning - Yap Aye Wee.pdfNUS-ISS
38 visualizações11 slides
MemVerge: Memory Viewer Software por
MemVerge: Memory Viewer SoftwareMemVerge: Memory Viewer Software
MemVerge: Memory Viewer SoftwareCXL Forum
118 visualizações10 slides
Data-centric AI and the convergence of data and model engineering: opportunit... por
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...Paolo Missier
29 visualizações40 slides

Último(20)

Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu... por NUS-ISS
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...
NUS-ISS32 visualizações
"Role of a CTO in software outsourcing company", Yuriy Nakonechnyy por Fwdays
"Role of a CTO in software outsourcing company", Yuriy Nakonechnyy"Role of a CTO in software outsourcing company", Yuriy Nakonechnyy
"Role of a CTO in software outsourcing company", Yuriy Nakonechnyy
Fwdays40 visualizações
Future of Learning - Khoong Chan Meng por NUS-ISS
Future of Learning - Khoong Chan MengFuture of Learning - Khoong Chan Meng
Future of Learning - Khoong Chan Meng
NUS-ISS31 visualizações
Future of Learning - Yap Aye Wee.pdf por NUS-ISS
Future of Learning - Yap Aye Wee.pdfFuture of Learning - Yap Aye Wee.pdf
Future of Learning - Yap Aye Wee.pdf
NUS-ISS38 visualizações
MemVerge: Memory Viewer Software por CXL Forum
MemVerge: Memory Viewer SoftwareMemVerge: Memory Viewer Software
MemVerge: Memory Viewer Software
CXL Forum118 visualizações
Data-centric AI and the convergence of data and model engineering: opportunit... por Paolo Missier
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...
Paolo Missier29 visualizações
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen... por NUS-ISS
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
NUS-ISS23 visualizações
"Ukrainian Mobile Banking Scaling in Practice. From 0 to 100 and beyond", Vad... por Fwdays
"Ukrainian Mobile Banking Scaling in Practice. From 0 to 100 and beyond", Vad..."Ukrainian Mobile Banking Scaling in Practice. From 0 to 100 and beyond", Vad...
"Ukrainian Mobile Banking Scaling in Practice. From 0 to 100 and beyond", Vad...
Fwdays40 visualizações
Transcript: The Details of Description Techniques tips and tangents on altern... por BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada119 visualizações
Tunable Laser (1).pptx por Hajira Mahmood
Tunable Laser (1).pptxTunable Laser (1).pptx
Tunable Laser (1).pptx
Hajira Mahmood21 visualizações
PharoJS - Zürich Smalltalk Group Meetup November 2023 por Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi113 visualizações
MemVerge: Gismo (Global IO-free Shared Memory Objects) por CXL Forum
MemVerge: Gismo (Global IO-free Shared Memory Objects)MemVerge: Gismo (Global IO-free Shared Memory Objects)
MemVerge: Gismo (Global IO-free Shared Memory Objects)
CXL Forum112 visualizações
The details of description: Techniques, tips, and tangents on alternative tex... por BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada110 visualizações
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor... por Vadym Kazulkin
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
Vadym Kazulkin70 visualizações
Spesifikasi Lengkap ASUS Vivobook Go 14 por Dot Semarang
Spesifikasi Lengkap ASUS Vivobook Go 14Spesifikasi Lengkap ASUS Vivobook Go 14
Spesifikasi Lengkap ASUS Vivobook Go 14
Dot Semarang35 visualizações
The Importance of Cybersecurity for Digital Transformation por NUS-ISS
The Importance of Cybersecurity for Digital TransformationThe Importance of Cybersecurity for Digital Transformation
The Importance of Cybersecurity for Digital Transformation
NUS-ISS25 visualizações
Liqid: Composable CXL Preview por CXL Forum
Liqid: Composable CXL PreviewLiqid: Composable CXL Preview
Liqid: Composable CXL Preview
CXL Forum121 visualizações
ChatGPT and AI for Web Developers por Maximiliano Firtman
ChatGPT and AI for Web DevelopersChatGPT and AI for Web Developers
ChatGPT and AI for Web Developers
Maximiliano Firtman174 visualizações
Micron CXL product and architecture update por CXL Forum
Micron CXL product and architecture updateMicron CXL product and architecture update
Micron CXL product and architecture update
CXL Forum27 visualizações

Asp.net,mvc

  • 1. ASP.NET and Model View Control Jesper Tørresø ITNET2 F08
  • 2. Turns around the usual way • A MVC Controller takes control over from the standard ASP.NET Framework View Engine. • From Scott Guthrie – ”The MVC framework supports using the existing ASP.NET .ASPX, .ASCX, and .Master markup files as "view templates" (meaning you can easily use existing ASP.NET features like nested master pages, <%= %> snippets, declarative server controls, templates, data-binding, localization, etc). It does not, however, use the existing post-back model for interactions back to the server. Instead, you'll route all end-user interactions to a Controller class instead - which helps ensure clean separation of concerns and testability (it also means no viewstate or page lifecycle with MVC based views). ”
  • 3. But what about the existing ASP.NET framework? • May we ”only” use HTML control and not server controls and/oe user controls? • All HTML from controls may be used • We can use the already known APS.NET server controls and also a special MVC User Control. (!!!!) • But we must take care of routing etc by our self.
  • 4. Model View Control JSP Model 1 architecture (from 1998-1999) Is this original ASP.NET ?
  • 5. Model View Control JSP Model 2 architecture
  • 6. Model, View and Controller: The pattern MVC, which stands for Model-View-Controller, separates an application in three components: • Model: this is where all the business logic of the application resides: it can range from a simple static class that returns a dataset to a complex multi-assembly Business Logic Layer that uses an assembly specific to the Data Access Layer. • View: at the other end of the application is the View, which displays the application's user interface and contains the representation of the data that have been retrieved by the Model. This doesn't have logic, other than the one strictly related to the presentation of data. • Controller: between the two components stands the Controller. It acts as the orchestrator of all the interactions among the other components and the users: it handles the requests, reads the form values, passes them to the Model, decides which View to render and finally sends the data to be rendered to the View.
  • 7. Interaction 1. The request comes from the client and hits the Controller. 2. The Controller calls the Model in order to perform some "business" operations. 3. The Model returns the results of the operations back to the Controller. 4. The Controller decides which View needs to be rendered and sends it the data that must be rendered. 5. Finally the View renders the output and sends the response back to the client.
  • 8. Model 2 and ASP.NET
  • 9. URL Routning • Normal ASP.NET – http://server/application/Products.aspx?id=4 • ASP.NET MVC – http://server/application/Products/show/beverages • The URL’s are interpreted by a RouteHandler and known as routes to the Controller.
  • 10. URL Routning 1 • The URL patterns defined are called routes Ex: Valid route definitions Examples of matching URL {controller}/{action}/{id} /Products/show/beverages {table}/Details.aspx /Products/Details.aspx blog/{action}/{entry} /blog/show/123 {reporttype}/{year}/{month}/{day} /sales/2008/1/5 Typically, you add routes in the handler for the Application_Start event in the Global.asax file. This approach makes sure that the routes are available when the application starts.
  • 11. URL Routning 2 • Initiating application in Global.asax.cs void Application_Start(object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); } public static void RegisterRoutes(RouteCollection routes) { routes.Add(new Route ( "Category/{action}/{categoryName}" new CategoryRouteHandler() ) { Defaults = new RouteValueDictionary {{"categoryName", "food"}, {"action", "show"}} } ); }
  • 12. URL Routning 3 • See more here – http://quickstarts.asp.net/3-5-extensions/mvc/URLR • Setting default values in Routes • Adding constraints Routes • Making a MVC route to a URL
  • 13. Sow! What is ASP.NET MVC? • ASP.NET MVC is a framework that allows developers to apply the MVC pattern in the development of an ASP.NET application, thus allowing a better separation of concerns, which results in better reusability and easier testing. • MVC was one of the concepts originally found in SmallTalk. MVC and the web seem like a match made in heaven and allow for a simple way of building complex web applications. • To understand why this recently re-discovered way of building web application was developed, we need to have a look at the pitfalls of the standard model, which is the web-form approach. – First, it is event based: it can be good or bad depending on how you look at it. Good because it helps VB6 and WinForms developers to smoothly migrate their skills to the web application development. Bad because there are dozens of events that are raised during the page life- cycle, and it's not trivial to understand where to put your code. Also because the process logic is tightly coupled with the page life- cycle, it is difficult to test using automated tests. Cont..
  • 14. Sow! What is ASP.NET MVC? cont. – It also uses server forms and ViewState: again, as with the event based model, it can be good since this hides to the developer all the problems related to maintaining the state of the page (values of textboxes, contents of dropdowns and so on), but can also be bad if you want to control exactly how the page is rendered, and you don't need to maintain all the state. – Furthermore, it uses server controls: good because they render the HTML for you; bad since they render it the way they want. • With the MVC framework you gain back the control of the order in which things happen during the page life-cycle, of the way state is persisted between requests, and the code with which HTML is rendered. And thanks to a better separation of concerns it's easier to test the process logic. But all this control has a cost: you have to do everything by yourself. • Keep in mind this: the MVC framework is not a replacement for the web- form programming model, but it's an alternative programming model, for those who want to have a better control and want to be able to also test the presentation logic