overview of code coverage & code...
TRANSCRIPT
.NET MVCa Jump Start
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
Meganadha Reddy K.Technical Trainer | NetCom Learning
www.NetComLearning.com
What is ASP.NET MVC ?
• A web application project type
• Points to note here is:
• It is not replacement for web forms
• Builds on top of ASP.NET
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
What is MVC for?
• Maintain Clean Separation of Concerns
• Extensible and Pluggable
• Enable clean URLs and HTML
• Integration with ASP.NET
• Easily testable
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
MVC
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
Model
View
Controller
MVC – How it works? (1 of 2)
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
Controller
View
Model
USER
Uses Manipulates
UpdatesSees
MVC – How it works? (2 of 2)
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
M, V, C – Definitions (1 of 2)
MVC stands for model-view-controller. MVC is a pattern for developing
applications that are well architected, testable and easy to maintain.
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
M, V, C – Definitions (2 of 2)
• Models: Classes that represent the data of the application and that use
validation logic to enforce business rules for that data.
• Views: Template files that your application uses to dynamically generate
HTML responses.
• Controllers: Classes that handle incoming browser requests, retrieve model
data, and then specify view templates that return a response to the browser.
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
Lets create a simple MVC project
From Visual Studio:
File “New Project”
Under “Web”
ASP.NET Web Application
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
Lets understand the default folders
Points to note here:
a. Folders for
i. Models
ii. Views
iii. Controllers
b. App_Start RouteConfig.cs
c. Global.asax
d. package.config
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
RouteConfig.cs
Will have default path or
route for the website
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
First MVC Application
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
Adding – Controller Class
Namespace
Controllers should inherit Controller
ActionResult is the return type here.
1
2
3
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
Adding – View
Step-1:
Add a folder “Home” inside “Views”
Step-2:
Right click on “Home”.
Add View [As shown]
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
Simple - Model
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
Updated Controller
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
ASP.NET MVC Request
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
MVC Templates in Visual Studio
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
Razor – Syntax (1 of 2)
19
@ - For values (HTML Encoded)
<p>
Current time is: !!!
</p>
@{ … } – For code blocks (keep the view simple!)
@{
}
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
Razor – Syntax (2 of 2)
• If, else, for, foreach, etc. C# statements
• HTML markup lines can be included at any part
• @: – For plain text line to be rendered
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
MVC Flow (Summary)
Request
Controller
Step 1
Incoming request directed to Controller
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
MVC Flow (Summary)
ControllerModel
Step 2
Controller processes request and forms a data Model
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
MVC Flow (Summary)
Controller
ViewStep 3
Model is passed to View
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
MVC Flow (Summary)
Controller
View
Step 4
View transforms Model into appropriate output format
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
MVC Flow (Summary)
Response
Controller
View
Step 5
Response is rendered
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/
Thank you
?
© Meganadha Reddy K., 2015 http://www.netcomlearning.com/