ASP.NET MVC Fundamental
Upcoming SlideShare
Loading in...5

Like this? Share it with your network

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads


Total Views
On Slideshare
From Embeds
Number of Embeds



Embeds 145 140 5

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide
  • 3Mins
  • Estimated Time: 5 minutesThe Microsoft Web Platform is a complete stack for running powerful, rich web applications that scale easily too. It’s also easy to install thanks to the Web Platform Installer – a free, one click download that gets everything setup for you very quickly!At the foundation of the platform is Windows Server and Internet Information Services which provides a really powerful web server which you can rely on to serve up your web applications. For storing your application data, SQL Server is a robust and secure database which scales effectively to deliver huge datasets. Moving up the stack, the most effective way to map data to your application code is the Entity Framework, which now in v4, provides an ORM that allows you to code against multiple data sources without concerning yourself with writing database centric calls. At the application layer there are a couple of choices thanks to the flexibility of ASP.NET – either ASP.NET Web Forms or ASP.NET MVC – we’ll be discussing both these in more detail a little later.On the client we support and contribute towards the jQuery Core Library and plugins making JavaScript development easier as well as providing the Ajax Control Toolkit for Web Forms developers to easily create rich web applications.On the tooling side, Visual Studio 2010 provides software, support and collaboration features to deliver cool web applications.NotesSome notes on security – if needed.Web Server.Note that these numbers are run against specific advisories against IIS or Apache, and for consistency, we’re looking at the most recent 2 versions of each.IIS had 8 Security advisories directly associated with it. (2 for IIS7, 6 for IIS 6)Apache had 56 Security advisories (17 for 2.2.x and 39 for 2.0.x)As of February 2010, IIS 7 has 0 unpatched advisories, and IIS 6 has 1 unpatched advisory. Apache 2.2.x has 2 unpatched advisories, and Apache 2.0.x has 4 unpatched advisories.Conclusion: Not only does IIS have less advisories against it, Microsoft also demonstrate that they are quicker to patch these advisories.DatabaseNote that these numbers are run against advisories for specific versions of SQL Server and MySQL. As such we’re using the most recent 2 versions of each.SQL Server had 4 Security advisories (0 for SQL Server 2008, 4 for SQL Server 2005)MySQL had 44 Security advisories (20 for MySQL 5.x, 22 for MySQL 4.x)As of February 2010, SQL Server had 0 unpatched advisories, and MySQL has 4 unpatched advisories.Conclusion: Not only does SQL Server have less advisories against it, Microsoft also demonstrate that they are quicker to patch these advisories.Application Framework.Note that ASP.NET is in the .NET framework, so the numbers are for the framework as a whole. Note also that as the advisories are published for specific versions, we’re looking at the last two versions of each..NET had 9 total advisories (2 for .NET 3.x, 7 for .NET 2.x)PHP had 28 total advisories (2 for 5.3.x, 26 for 5.2.x)There are 0 unpatched advisories for /NET, there are 5 unpatched advisories for PHP.
  • 2 minutesWhen we look at all the different profiles of people creating websites we see certain patterns emerge. First, there is a group of people that want to easily create simple web sites to share information about their hobbies, work, to share photos, and so on. Web Apps are overkills for them. They just need to get the site up and running rapidly from scratch.There’s another group of people that like to use the large number of rich web applications out there as a starting point, they need to get to a solution quickly and in an easy way. Many of this web apps are tailored for specific tasks, and provide 80% of the functionality of a solution; the developer just need to customize them and publish them.Finally, there are the professional developers that need to build complex and scalable web sites. For this, they need tools that help them work in a team, source and version control, a testing framework, and tools with lots of powerful extensions.
  • The ASP.NET MVC simplifies the complex parts of Web Forms without any compromise of the power and flexibility of ASP.NET platform. MVC implements Model-View-Controller UI pattern for web application development that lets you allows to develop applications in a loosely couples manner. MVC pattern is separating the application in three parts- Model, View and Controller. A view is responsible for rendering the user interface (UI) of the application and it is nothing more than html templates that filled with application’s data passed by the controller. The Model implements the logic for the application's data and it represents the business objects of the application that using the View for rendering user interface. Controllers are handles and responds to user input and interaction. The web request will be handled by the controller, and the controller will decide which model objects to use and which view objects to render. The MVC model replaces the Web Form events with the controller actions. The main advantages of the MVC models are clear separation of concerns, unit testing facility, and more control over the URLs and HTML. The MVC model does not use Viewstate, Postbacks, Server controls, and server-based forms that enable full control over the application and html rendered by the Views. MVC model is using Representational state transfer (REST) based URLs instead of file-name extensions used by the Web Form model so that we can make search engine optimization (SEO) URLs published by the application
  • Estimated Time: 2 mins
  • Estimated Time: 2 minutesFinally, we got to the C (from MVC), the Controllers.Controllers are responsible of receiving user requests and taking care of them accordingly. In general, controllers would create a model, which they fill with data from a persistence source like a database and pass it to a view.
  • Estimated Time: 2 minutesLet’s first start by the M (of MVC), the Models.Models are the mean of communication between the controllers and the views. Whenever a controller processes a request from the user and has to display information, it creates the model and passes it to the view. The model only holds data. It doesn’t know anything about the application logic or how to display itself.
  • Estimated Time: 2 minutesNow let’s continue with the V (from MVC), the Views.Views are visual representations of the models. They are responsible for displaying a model or part of it to the user. The views don’t hold application logic.Note that there can be many views of the same model. Maybe one view displays the name and address of a customer while other displays the telephone and the orders from that same customer but both rely on the same model: the customer.
  • Estimated Time: 3 minutesThe primary framework goals of ASP.NET MVC are…Frictionless testability– By “frictionless” I mean that when you want to test your code, the framework it was written it doesn’t cause you friction. This is very important if you want to seriously perform long-term unit testing on an application, because if developers were constantly running into points of friction when trying to test, they would eventually abandon it.Tight cover over markup – ASP.NET MVC doesn’t contain any server controls or high-level abstractions that mask their underlying rendering. When you develop an ASP.NET MVC application, you have complete control over the markup. ASP.NET MVC does include some HTML helpers that “hide” away some HTML, but they are at the most basic level of rendering (i.e. just an element).Leverage the benefits of ASP.NET – Because ASP.NET MVC is built on top of the core ASP.NET runtime, you still have plenty of old-friends that can be used (i.e. profiles, membership, roles, caching). All of the same intrinsics you’ve always known are still valid and used heavily.Conventions and guidance – ASP.NET MVC comes with a set of predefined conventions that make the use of it much easier, without the need to for tons of configuration. It also provides framework-level guidance. The idea is that ASP.NET MVC wants to try to lead developers down the pit of success.


  • 1. ASP.NET MVC 3 Training for Heroes
  • 2. Who am I?
    Technical evangelism
    Software engineer at Vina Digital Co,. Ltd.
  • 3. Active Server Pages
    Visual Studio 98:
    ASP, VBScript, ADO
    Request, Response object
  • 4. Evolution of #2: ASP 1.0, 1.1, 2.0 1.0: January 16th 2002 1.1: April 24th 2003 2.0: Nov 7th 2005, Visual Studio 2005
    New data controls (GridView, FormView, DetailsView)
    Declarative data access (SqlDataSource, ObjectDataSource, XmlDataSource controls)
    Navigation controls
    Master pages
    Login controls
    Web parts
    Personalization services
    Full pre-compilation
    New localization technique
    Support for 64-bit processors
    Provider class model
    Code Behind,Web Form,
  • 5. 3.0, 3.5, 3.5 SP 1 3.0: Nov 21 2006 : WCF, CardSpace 3.5: Nov 19 2007, released with VS2008:
    LINQ Data Source
    New data controls (ListView, DataPager)
    ASP.NET AJAX included as part of the framework
    Support for HTTP pipelining and syndication feeds.
    WCF Support for RSS, JSON, POX and Partial Trust 3.5 sp1: Aug 11 2008:
    Dynamic Data
    Browser history in an ASP.NET AJAX
    Combine multiple Javascript files into a single file
    New namespaces System.Web.Abstraction and System.Web.Routing
    ASP.NET 4.0
    Easier to get started, develop and deploy
    Routing and Search Engine Optimization
    Productivity & Extensibility
  • 6. The Microsoft Web Platform
    Web Platform Installer
    Ajax Control Toolkit & jQuery
    ADO.NET Entity Framework
    SQL Server
    The Microsoft Web Platform combines a rich and powerful web application framework with a supporting cast of tools, servers,technologies and applications for creating, designing, developing and delivering web solutions.
  • 7. Web Platform Installer
    Makes it easy to install the Microsoft Web Platform from one place
    Framework, Web Server, Database and Tools
    Cost = free; Size < 2MB
    Always has latest version of the platform available
    Available in 9 languages
    Web App Gallery
    Umbraco, DotNetNuke, Drupal, WordPress and many more
    Submit your own apps, get distribution
  • 8. Today’s Web Developers
    I want to build web sites myself with an easy to learn tool and framework
    I’m a professional software developer and I build complex, large scale web sites with a team of developers
    I <3 Web Apps. I just need a tool that makes them easier to configure, customize and publish them
  • 9. Goals of ASP.NET MVC
    Clean URL schemes
    Support existing ASP.NET runtime features
    Build on top of System.Web, doesn’t replace it
    Enable clean separation of concerns
    Testable by default (built with TDD in mind)
    Support third-party view engines
    Auto-mapping of form variables to object properties
    Provides complete control over your HTML markup
    Enables rich JavaScript, AJAX integration
  • 10. Key Concepts
  • 11. MVC Pattern
    Decouples the backend business logic from the front end
    Binds the model and view together and selects which view to display next
    Data Transfer
    Event Notification
    Data Transfer
    Business InteractionLayer
    User InteractionLayer
    Visualizes the application data supplied by the model
  • 12. How MVC Works
    What does MVC look like?
    Retrieves Model
    “Does Stuff”
    Visually represents
    the model
  • 13. Introducing “MVC Shine” application
    View detail about mvc activities of heroes
    Rate an activity
    What you are doing to see today
    Build the first ASP.NET MVC application
    ASPX view engine
    Learning about ASP.NET MVC 3 fundamental
    Razor view engine
    Implementing simple functionalities (CRUD, master-detail)
  • 14. Controllers
    Controllers handle requests from the user
    Controllers create the model for the views
    Application logic is placed in the controllers
  • 15. Models
    The models hold the application data
    Models are the mean of communication between the controllers and the views
    Models hold no application logic
    Views are visual representations of a model
    There can be many views for the same model
    Views contain no application logic
  • 17. URL routing
    Web form: without query string, an URL maps to one aspx page
    MVC: URL maps to Controller/Action/RoutesValues
    Controller = CompanyController
    Action = Details
    Route Value = {ID = 3}
    Controller = NewsController
    Action = Index
    Route Value = null
  • 18. Action Result
    The ActionResultclass is the base for all action results. However, there are different action result types, depending on the task that the action method is performing.
    The most common action is to call the View method. The View method returns an instance of the ViewResultclass, which is derived from ActionResult.
  • 19. Action Result Examples
    Return JSON
    public ActionResultGetSubSkill(int id)
    return Json(db.GetSkills(id)); //Return data in JSON format
    $.getJSON("/Skill/GetSubSkill/" + $(this).attr("id"), function(data) {
    Returns JavaScript
    public JavaScriptResultJAction()
    return JavaScript("alert('HelloWorld')");

    <script type="text/javascript" src="/Home/JAction"></script>
  • 20. MVC UI Helper Controls
    The HtmlHelper class renders Html fragments of views.
    Basic MVC UI Helper Controls
    Html.ActionLink(), Html.BeginForm(), Html.CheckBox(), Html.DropDownList(), Html.EndForm(), Html.Hidden(), Html.ListBox(), Html.Password(), Html.RadioButton(), Html.TextArea(), Html.TextBox()
    MVC UI Helper Controls can be extended using extension method.
  • 21. Framework Goals
    Frictionless Testability
    Tight control over <markup>
    Leverage the benefits of ASP.NET
    Conventions and Guidance
  • 22. MVC vs Web Form
    MVC is just another choice of technologies for web development using ASP.NET.
    Web forms is still well developed and supported