Complete AET MVC Course

Jul 19, 2024

Complete AET MVC Course

Introduction

  • Instructor: M. Shadani
  • Course Objective: Build Vidly Application (Video Rental Store System)
    • Roles: Admin, Staff Member
    • Features: Manage customers, movies, rentals
    • Business rules: Age validation for memberships, movie availability

Application Overview

  • Admin View: Full access to customers, movies, and rentals
  • Staff Member View: Read-only access to movies
  • Guest Login: Facebook authentication with potential for extending to Google and Twitter

MVC Architecture

  • MVC stands for Model View Controller
  • History: Developed for desktop applications in the 1970s, widely adopted for web applications
  • Components:
    • Model: Represents application data and rules (e.g., movie, customer, rental transaction)
    • View: HTML markup for displaying data
    • Controller: Handles HTTP requests (
      • Example: URL /movies handled by MoviesController
    • Router: Selects the appropriate controller based on URL

Tools Required

  • Visual Studio 2013 or Higher
  • Plugins:
    • Productivity Power Tools 2013
    • Web Essentials
    • Optional: Resharper

Development Environment Setup

  • Creating projects in Visual Studio
    • Templates > Visual C# > Web > ASP.NET Web Application > MVC Template
    • Optional: Source Control with Git
  • Project Structure
    • App_Data: Contains database files
    • App_Start: Configuration classes (e.g., RouteConfig)
    • Content: CSS files, images
    • Controllers: Handles HTTP requests
    • Models: Domain classes
    • Scripts: JavaScript files
    • Views: HTML views
    • Global.asax: Application lifecycle events
    • Web.config: Application configurations (e.g., connection strings)

Building Blocks of MVC

  • Creating Models: Example movie model with properties ID and Name
  • Creating Controllers: Example MoviesController with action Random
  • Returning Views from Controller Actions
  • Debugging common issues with URLs and Parameters

ASP.NET MVC Fundamentals

  • Action Results: Different types including ViewResult, PartialViewResult, ContentResult, etc.
  • Action Parameters: Mapping request data to action parameters
  • Routing: Default and custom routes
  • Attribute Routing: Cleaner and easier method for creating routes using attributes on actions

Working with Views

  • Razor View Engine: Using @model, mixing HTML and C# code
  • Partial Views: Reusable smaller views
  • Passing Data to Views:
    • Via Model (preferred method)
    • Using ViewData and ViewBag (less preferred, not type-safe)
  • View Models: Combining multiple models into a single view model for complex views
  • Dynamic Class Rendering and Conditional Rendering: Using Razor syntax

Practical Exercise

  • Implementing list and details pages for customers and movies
  • Visualizing implementation through GitHub repository with step-by-step commits

Next Steps

  • Upcoming topics: Entity Framework, RESTful services, client-side development, authentication, performance optimization, building and deployment

Bonus Section

  • Complete Course on Udemy: Detailed course with exercises and real-world examples

Key Takeaways

  • Understanding MVC architecture and its components
  • Setting up a development environment
  • Basics of working with ASP.NET MVC including routing, views, and controllers
  • Practical implementation of concepts with the Vidly application