Introduction to Mvc

29
MVC Part 1 06/14/2022 Infobest Romania

description

Internal MVC training

Transcript of Introduction to Mvc

Page 1: Introduction to Mvc

04/13/2023Infobest Romania

MVCPart 1

Page 2: Introduction to Mvc

04/13/2023Infobest Romania

MVC Architecture M, V and C Separation of Concerns .NET MVC Framework Demo

Topics

Create a project.How is it configured by default? Model, View Controller Razor Routing Friendly URLs Test driven dev Bundling Minification Validation Forms Send data to controller from view Form security

Page 3: Introduction to Mvc

04/13/2023Infobest Romania

MVC Architecture

Page 4: Introduction to Mvc

04/13/2023Infobest Romania

Players

Controller:  - Handles a request from a View and updates the Model that results in a change of the Model's state.

- Sends Data to View

Model: The business entity on which the overall application operates. Many applications use a persistent storage mechanism (such as a database) to store data. MVC does not specifically mention the data access layer because it is understood to be encapsulated by the Model. 

View: The user interface that renders the Model into a form of interaction. 

MVC Architecture

Page 5: Introduction to Mvc

04/13/2023Infobest Romania

To implement MVC in .NET we need mainly three classes (View, Controller and the

Model). 

MVC Architecture

Page 6: Introduction to Mvc

04/13/2023Infobest Romania

The process of breaking a computer program into distinct features that overlap in functionality as little as possible

MVC design pattern aims to separate content from presentation and data-processing from content. Theoretically sound, but where do we see this in MVC? One place is reasonably clear - between the data-processing (Model) and the rest of the application.

Separation of Concern

Page 7: Introduction to Mvc

04/13/2023Infobest Romania

Separation of Concern

Page 8: Introduction to Mvc

04/13/2023Infobest Romania

Thus our models, controllers and views lie in logical/physical layers independent of each

other.

Separation of Concern

Page 9: Introduction to Mvc

04/13/2023Infobest Romania

.NET MVC Framework

Page 10: Introduction to Mvc

04/13/2023Infobest Romania

.NET Framework

Page 11: Introduction to Mvc

04/13/2023Infobest Romania

Demo Create a project.How is it configured by default? Model, View Controller Razor Routing Friendly URLs Test driven dev Bundling Minification Validation Forms Send data to controller from view Form security

Page 12: Introduction to Mvc

04/13/2023Infobest Romania

Demo : Create a project.How is it configured by default?

Page 13: Introduction to Mvc

04/13/2023Infobest Romania

Demo : Model, View Controller

Page 14: Introduction to Mvc

04/13/2023Infobest Romania

Demo : Razor

Page 15: Introduction to Mvc

04/13/2023Infobest Romania

Demo : Routing

Page 16: Introduction to Mvc

04/13/2023Infobest Romania

Demo : Friendly URLs

Page 17: Introduction to Mvc

04/13/2023Infobest Romania

Demo : Test driven development

Page 18: Introduction to Mvc

04/13/2023Infobest Romania

Demo : Bundling + Optimization

Page 19: Introduction to Mvc

04/13/2023Infobest Romania

 ”In addition, the facility exists to optimise (minify) the CSS and Script files for release builds, whilst at the same time providing normal scripts for debugging the web application.” http://johnnewcombe.net/blog/post/4

Demo : Bundling

Page 20: Introduction to Mvc

04/13/2023Infobest Romania

Page 21: Introduction to Mvc

04/13/2023Infobest Romania

Demo : Bundling

Page 22: Introduction to Mvc

04/13/2023Infobest Romania

Demo : Bundling

Page 23: Introduction to Mvc

04/13/2023Infobest Romania

BundleTable.EnableOptimizations = true;

Demo : Bundling

Page 25: Introduction to Mvc

04/13/2023Infobest Romania

Demo : Model Validation

Page 26: Introduction to Mvc

04/13/2023Infobest Romania

@using (Html.BeginForm("Index", "Test")) { … <input type=“submit”

id=“submitIndexView”/> }

Demo : Forms

Page 27: Introduction to Mvc

04/13/2023Infobest Romania

@using (Html.BeginForm("Index", “Test“ ,new {argTest = "someText"}))

{ … <input type=“submit”

id=“submitIndexView”/> }

Demo : Send data to controller from view

Page 28: Introduction to Mvc

04/13/2023Infobest Romania

For View @Html.AntiForgeryToken()

For Controller [HttpPost] [ValidateAntiForgeryToken]

Demo : Form security

Page 29: Introduction to Mvc

04/13/2023Infobest Romania

Thanks!Claudiu Socaci