SlideShare a Scribd company logo
ASP.NET MVC
Bhavin Shah
Software Engineer @ Sfw India Pvt. Ltd .
Agenda
Beforehand – ASP.NET Web Forms
What is MVC
What is ASP.NET MVC?
Models
Views
Controllers
Validation
Routing
Unit Tests
View engines
2
ASP.NET Web Forms
Rich controls and tools
Postbacks
Event driven web development
Viewstate
Less control over the HTML
Hard to test
Rapid development
3
Let’s chat for a bit…
4
What is MVC
5
Model – View - Controller
6
Controller - responsible for handling all user
input
Model - represents the logic of the application
View - the visual representation of the model
ASP.NET MVC
More control over HTML
No Codebehind
Separation of concerns
Easy to test
URL routing
No postbacks
No ViewState
7
Models
The model should contain all of the application
business logic, validation logic, and database
access logic.
ASP.NET MVC is compatible with any data
access technology (for example LINQ to SQL)
All .edmx files, .dbml files etc. are located in
the Models folder.
8
Custom View Models
9
When you combine properties to display on a
View
namespace ContosoUniversity.ViewModels
{
public class AssignedCourseData
{
public int CourseID { get; set; }
public string Title { get; set; }
public bool Assigned { get; set; }
}
}
Creating a Model - DEMO
10
What is Controller?
It is a class
Derives from the base
System.Web.Mvc.Controller class
Generates the response to the browser request
11
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View();
}
public ActionResult About()
{
return View();
}
}
Controller Actions
Public method of the Controller class
Cannot be overloaded
Cannot be a static method
Returns action result
12
public ActionResult About()
{
return View();
}
Action Results
Controller action response to a browser
request
Inherits from the base ActionResult class
Different results types
13
Implement a Controller -
DEMO
14
Action Results Types
ViewResult
EmptyResult
RedirectResult
JsonResult
JavaScriptResult
ContentResult
FileContentResult
FileStreamResult
FilePathResult
15
Controller base class
methodsView
Redirect
RedirectToAction
RedirectToRoute
Json
JavaScriptResult
Content
File
16
Views
Most of the Controller Actions return views
The path to the view is inferred from the name
of the controller and the name of the
controller action.
ViewsControllerNameControllerAction.aspx
A view is a standard (X)HTML document that
can contain scripts.
script delimiters <% and %> in the views
17
Pass Data to a View
With ViewData:
ViewData["message"] = "Hello World!";
Strongly typed ViewData:
− ViewData.Model = OurModel;
With ViewBag:
ViewBag.Message = "Hello World!";
18
Post data to a controller
Verb Attributes
The action method in the controller accepts the
values posted from the view.
The view form fields must match the same
names in the controller.
19
[HttpPost]
public ActionResult Edit(Movie movie)
{
if (ModelState.IsValid)
{
db.Entry(movie).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(movie);
}
Explore a View - DEMO
20
HTML Helpers
Methods which typically return string.
Used to generate standard HTML elements
textboxes, dropdown lists, links etc.
Example: Html.TextBox() method
Usage is optional
You can create your own HTML Helpers
21
Validation
Two types of validation error messages
generated before the HTML form fields are
bound to a class
generated after the form fields are bound to the
class
Model State
Validation Helpers
Html.ValidationMessage()
Html.ValidationSummary()
22
ventsypopov.com
Implement validation- DEMO
23
Routing
The Routing module is responsible for
mapping incoming browser requests to
particular MVC controller actions.
Two places to setup:
Web.config file
Global.asax file
24
Routing Setup
Web.config file
25
<system.web>
<httpModules>
…
<system.web>
<httpHandlers>
…
<system.webServer>
<modules> …
<system.webServer>
<handlers>
…
Routing Setup
Global.asax file
26
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home",
action = "Index", id = "" }
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
}
URL Example
http://www.mysite.com/Home/About/6
{controller} = Home
{action} = About
{id} = 6
27
ventsypopov.com
Routing example - DEMO
28
ventsypopov.com
Unit Tests
Used for the business logic (not DAL or View
logic).
Test individual “unit”of code
Make the code safe to modify
Mock Object framework
When you lack “real” objects
Create mocks for the classes in the application
Test with mock objects
29
Unit Tests - DEMO
30
ventsypopov.com
View Engines
Handles the rendering of the view to UI
(html/xml);
Different view engines have different syntax
ASP.NET MVC 3 Pre-included View Engines:
Web Forms
Razor
31
View Engines - DEMO
32
Things to remember
What MVC stands for
How ASP.NET MVC differs from Web Forms
Where is routing configured
How to validate business logic
How to use helpers
Unit tests basics
Choice between “View Engines”
33
Useful sites
http://www.asp.net/mvc
http://msdn.microsoft.com/en-us/library/dd39470
http://stackoverflow.com/
http://jquery.com/
34
ASP.NET MVC
Email: bhavinshah1988@gmail.com
Time to wake up :)
36

More Related Content

What's hot (20)

PPTX
ASP.NET MVC Presentation
Volkan Uzun
 
PDF
Angular - Chapter 4 - Data and Event Handling
WebStackAcademy
 
PPT
Asp.net.
Naveen Sihag
 
PPT
Angular 8
Sunil OS
 
PPTX
Angular 14.pptx
MohaNedGhawar
 
PPTX
Introduction to angular with a simple but complete project
Jadson Santos
 
PDF
MVC architecture
Emily Bauman
 
PPTX
Introduction to ASP.NET
Rajkumarsoy
 
PDF
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Edureka!
 
PPTX
Angularjs PPT
Amit Baghel
 
PPTX
Angular 5 presentation for beginners
Imran Qasim
 
PPTX
Introduction to mvc architecture
ravindraquicsolv
 
PPTX
Lab #2: Introduction to Javascript
Walid Ashraf
 
PDF
Angular directives and pipes
Knoldus Inc.
 
PPTX
Introduction to Angularjs
Manish Shekhawat
 
PPTX
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Malla Reddy University
 
PPTX
Angular
sridhiya
 
PPSX
Asp.net mvc
Er. Kamal Bhusal
 
PPTX
Asp.Net Core MVC with Entity Framework
Shravan A
 
PPTX
Express js
Manav Prasad
 
ASP.NET MVC Presentation
Volkan Uzun
 
Angular - Chapter 4 - Data and Event Handling
WebStackAcademy
 
Asp.net.
Naveen Sihag
 
Angular 8
Sunil OS
 
Angular 14.pptx
MohaNedGhawar
 
Introduction to angular with a simple but complete project
Jadson Santos
 
MVC architecture
Emily Bauman
 
Introduction to ASP.NET
Rajkumarsoy
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Edureka!
 
Angularjs PPT
Amit Baghel
 
Angular 5 presentation for beginners
Imran Qasim
 
Introduction to mvc architecture
ravindraquicsolv
 
Lab #2: Introduction to Javascript
Walid Ashraf
 
Angular directives and pipes
Knoldus Inc.
 
Introduction to Angularjs
Manish Shekhawat
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Malla Reddy University
 
Angular
sridhiya
 
Asp.net mvc
Er. Kamal Bhusal
 
Asp.Net Core MVC with Entity Framework
Shravan A
 
Express js
Manav Prasad
 

Similar to MVC ppt presentation (20)

PPT
ASP.NET-MVC-Part-1.ppt
Saraswathi Ramesh
 
DOCX
LearningMVCWithLINQToSQL
Akhil Mittal
 
PPTX
Introduction to ASP.Net MVC
Sagar Kamate
 
PPTX
ASP.MVC Training
Mahesh Sikakolli
 
PPTX
Hanselman lipton asp_connections_ams304_mvc
denemedeniz
 
PPTX
Getting started with MVC 5 and Visual Studio 2013
Thomas Robbins
 
PDF
Aspnetmvc 1
Fajar Baskoro
 
PDF
Asp 1a-aspnetmvc
Fajar Baskoro
 
PPTX
Asp.Net MVC 5 in Arabic
Haitham Shaddad
 
PPTX
ASP.NET MVC 5 - EF 6 - VS2015
Hossein Zahed
 
PPS
Introduction To Mvc
Volkan Uzun
 
PPTX
MVC & SQL_In_1_Hour
Dilip Patel
 
PPTX
Asp.Net MVC Intro
Stefano Paluello
 
PPTX
Aspnet mvc
Hiep Luong
 
PPTX
Asp.net c# MVC-5 Training-Day-1 of Day-9
AHM Pervej Kabir
 
PDF
Applying Domain Driven Design on Asp.net MVC – Part 1: Asp.net MVC
Mohamed Meligy
 
PPTX
ASP.net MVC Introduction Wikilogia (nov 2014)
Hatem Hamad
 
PDF
Asp 1-mvc introduction
Fajar Baskoro
 
PPT
Asp.net,mvc
Prashant Kumar
 
PDF
ASP.NET MVC 2.0
Buu Nguyen
 
ASP.NET-MVC-Part-1.ppt
Saraswathi Ramesh
 
LearningMVCWithLINQToSQL
Akhil Mittal
 
Introduction to ASP.Net MVC
Sagar Kamate
 
ASP.MVC Training
Mahesh Sikakolli
 
Hanselman lipton asp_connections_ams304_mvc
denemedeniz
 
Getting started with MVC 5 and Visual Studio 2013
Thomas Robbins
 
Aspnetmvc 1
Fajar Baskoro
 
Asp 1a-aspnetmvc
Fajar Baskoro
 
Asp.Net MVC 5 in Arabic
Haitham Shaddad
 
ASP.NET MVC 5 - EF 6 - VS2015
Hossein Zahed
 
Introduction To Mvc
Volkan Uzun
 
MVC & SQL_In_1_Hour
Dilip Patel
 
Asp.Net MVC Intro
Stefano Paluello
 
Aspnet mvc
Hiep Luong
 
Asp.net c# MVC-5 Training-Day-1 of Day-9
AHM Pervej Kabir
 
Applying Domain Driven Design on Asp.net MVC – Part 1: Asp.net MVC
Mohamed Meligy
 
ASP.net MVC Introduction Wikilogia (nov 2014)
Hatem Hamad
 
Asp 1-mvc introduction
Fajar Baskoro
 
Asp.net,mvc
Prashant Kumar
 
ASP.NET MVC 2.0
Buu Nguyen
 
Ad

More from Bhavin Shah (6)

PPTX
Node Session - 4
Bhavin Shah
 
PPTX
Node Session - 3
Bhavin Shah
 
PPTX
Node Session - 2
Bhavin Shah
 
PPTX
Node Session - 1
Bhavin Shah
 
PDF
What is Penetration & Penetration test ?
Bhavin Shah
 
PDF
Cyber security
Bhavin Shah
 
Node Session - 4
Bhavin Shah
 
Node Session - 3
Bhavin Shah
 
Node Session - 2
Bhavin Shah
 
Node Session - 1
Bhavin Shah
 
What is Penetration & Penetration test ?
Bhavin Shah
 
Cyber security
Bhavin Shah
 
Ad

Recently uploaded (20)

PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 

MVC ppt presentation

Editor's Notes

  • #6: Анализ при архитектурни решения – взимаме стратегически решения свързани с бизнес нуждите на системата, която изграждаме. Обмисляме сигурност, производителност, поддръжка, надеждност, интеграция с тестови приложения, леснота и удобство на употреба на системата. Проблеми, с които се сблъскваме: Честа смяна на потребителски интерфейс Различно представяне на едни и същи данни Работа върху различни устройства Улеснено модулно тестване на системата Как да ги решаваме: Независимост на отделните модули Преизползваемост на модулите Добра структурна организация на системата
  • #16: Viewresult - If you want an action method to result in a rendered view, the action method should return a call to the controller&amp;apos;s View helper method. The View helper method passes a ViewResult object to the ASP.NET MVC framework, which calls the object&amp;apos;s ExecuteResult method. JsonResult - Represents a class that is used to send JSON-formatted content to the response. JavaScriptResult - Sends JavaScript content to the response. ContentResult - Represents a user-defined content type that is the result of an action method. FileContntResult - Represents a class that is used to send binary file content to the response FileStreamResult - Sends binary content to the response by using a Stream instance. FilePathResult - Sends the contents of a file to the response
  • #17: View - Creates a ViewResult object that renders a view to the response. Redirect - Creates a RedirectResult object that redirects to the specified URL. RedirectToAction - Redirects to the specified action using the action name Json - Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format. JavaScript - Creates a JavaScriptResult object Content - Creates a content result object by using a string. File - Creates a FileContentResult object by using the file contents and file type.
  • #22: To create HTML helper – a class with public static string methods and refer the namespace in the view.
  • #23: Html.ValidationMessage() - Displays a validation message if an error exists for the specified field in the ModelStateDictionary object Html.ValidationSummary() - Returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object.