+ All Categories
Home > Software > Asp.net mvc

Asp.net mvc

Date post: 12-Apr-2017
Category:
Upload: taranjeet-singh
View: 185 times
Download: 0 times
Share this document with a friend
21
ASP.NET MVC ASP.NET MVC [M [M odel odel V V iew iew C C ontroller ontroller (MVC) applications by (MVC) applications by using the ASP.NET using the ASP.NET framework framework] Taranjeet Singh www.ptlsolution .com
Transcript
Page 1: Asp.net mvc

ASP.NET MVCASP.NET MVC

[M[Model odel VView iew CController (MVC) ontroller (MVC) applications by using the applications by using the

ASP.NET frameworkASP.NET framework]

Taranjeet Singh

www.ptlsolution.com

Page 2: Asp.net mvc

What is ASP.NET MVC?

Saying simply, ASP.NET MVC is a new framework from Microsoft that sites over standard ASP.NET engine.

ASP.NET

ASP.NET MVC

Page 3: Asp.net mvc

ASP.NET MVC Features

What new does ASP.NET MVC bring in terms of web architecture?

1. Clear separation of logic: Model, View, Controller

2. Test-Driven Development

3. Full control over HTML and JavaScript

4. Friendly URLs

Page 4: Asp.net mvc

Model + View + Controller = MVC

ASP.NET MVC provides an alternative to the ASP.NET “Web Forms” pattern for creating MVC-based Web applications.

Model

ControllerView

Model objects implement the logic for the application's data domain. Often, model objects retrieve and store the app state in a database.

Controllers handle user interaction, work with the model, and select a view to render that displays UI

Views display the application's user interface (UI). Typically, this UI is created from the model data.

Page 5: Asp.net mvc

Request

ControllerController

Page 6: Asp.net mvc

ControllerController

Model

Page 7: Asp.net mvc

ControllerController

ViewView

Page 8: Asp.net mvc

ControllerController

ViewView

Page 9: Asp.net mvc

Response

ControllerController

ViewView

Page 10: Asp.net mvc

Full control over HTML & JS

In ASP.NET MVC, designed HTML & JS pages are not more messed up with “postbacks” and “ViewStates”, which is specific for “Web-forms” pattern.

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPaA8FDzhjYjBhZjA0ODYyMTM2NBgGBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WAQUhY3RsMDAkaGVhZGVyJHVjTWFpbk1lbnUkc2VhcmNoQnRuBTdjdGwwMCRNYWluQ29udGVudCRycHRWaWRlbyRjdGwwMyRwcmVzZW50YXRpb25DYXJkJG11bHRp" />

<script type="text/javascript">//<![CDATA[var theForm = document.forms['aspnetForm'];function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); }}//]]></script>

Page 11: Asp.net mvc

Friendly URLs

MVC binds web paths to the logical URLs rather than to the physical files.

C:\Inetpub\wwwroot\WebSite\Products.aspx

http://www.website.com/Products.aspx?name=Meat

http://www.website.com/Products/Meat

Physical location:

ASP.NET style:

MVC style:

Page 12: Asp.net mvc

RoutingR => the hidden characterMVC + R

1. Maps incoming URLs to the application and routes them to the right Controller’s Action method to execute them

2. Happens in RegisterRoutes function in the global.asax file

Page 13: Asp.net mvc

Routing

Don’t settle for…

/ProductsDetails.aspx?CategoryID=123

When you can easily have…

/Product/Details/123/

Or whatever else makes sense…

Page 14: Asp.net mvc

Routing

To customize routing rules

Page 15: Asp.net mvc

How does ASP.NET MVC looks like?

ASP.NET MVC installs a new type of web project into VS2013.

Page 16: Asp.net mvc

How does ASP.NET MVC looks like?

A newly created project has an ASP.NET MVC specific directory structure.

App_Data folder is the physical store for data.

Content folder keeps files such as scripts, CSS, images, and so on.

Controllers folder is the location for controllers. The MVC framework requires the names of all controllers to end with "Controller"—for example, HomeController, LoginController, or ProductController.

Models stores classes that handle application business logic.

Scripts folder is for script files that support the application. By default, this folder contains AJAX script files and the JQuery library.

Views is the recommended location for views. Views use .aspx, .ascx, and .master files, in addition to any other files that are related to rendering views.

Page 17: Asp.net mvc

Logic UI

Page 18: Asp.net mvc

Test-Driven Development

Since the UI is completely separated from the business logic, it’s now easy to write Unit Tests for the ASP.NET MVC application.

Controller

Unit Tests that cover User Actions and Data Model

User Interface Data Objects

Page 19: Asp.net mvc

Conclusion

ASP.NET MVC supports pure MVC pattern, the same development pattern Rails are based on. The advantages of ASP.NET MVC applications:

1. It makes it easier to manage complexity by dividing an application into the model, the view, and the controller.

2. It does not use view state or server-based forms. 3. It uses a Front Controller pattern that processes Web application

requests through a single controller. This enables you to design an application that supports a rich routing infrastructure with friendly URLs.

4. It provides better support for test-driven development (TDD).5. It works well for Web applications that are supported by large teams of

developers and Web designers who need a high degree of control over the application behavior.

Page 20: Asp.net mvc

Web Links to Additional Resources

• http://www.asp.net/mvc - official site

• http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx - development basics on ASP.NET MVC

• http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx - URL routing used in ASP.NET MVC

• http://weblogs.asp.net/scottgu/archive/2007/12/06/asp-net-mvc-framework-part-3-passing-viewdata-from-controllers-to-views.aspx - interaction between Controllers and Views

• http://weblogs.asp.net/scottgu/archive/2007/12/09/asp-net-mvc-framework-part-4-handling-form-edit-and-post-scenarios.aspx - managing form input data

Page 21: Asp.net mvc

Recommended