creating-the-list-page-slides
creating-the-list-page-slides
Gill Cleeren
CTO XPIRIT BELGIUM
@gillcleeren www.snowball.be
Overview Hello MVC
Creating the model and the repository
Creating the controller
Adding the view
Styling the view
Demo
Model-View-Controller
- Architectural pattern
- Separation of concerns
- Promotes testability and maintainability
The MVC in ASP.NET Core MVC
Controller
View Model
The MVC in ASP.NET Core MVC
Controller
View Model
The MVC in ASP.NET Core MVC
Controller
View Model
The MVC in ASP.NET Core MVC
Request
Controller
Update Update
View Model
Get data from
The MVC in ASP.NET Core MVC
ASP.NET Core
Creating the Model and the Repository
Using the Correct Folders
The Model
Services
Repository “Consumer” class
Startup
class
public void ConfigureServices(IServiceCollection services)
{
//register framework services
services.AddMvc();
HTML template
- *.cshtml
“Plain” or strongly-typed
Uses Razor
Matching the Controller and its Views
PieController
Matching the Action With the View
}
A Strongly-typed View
@model IEnumerable<Pie>
<html>
<body>
<div>
@foreach (var pie in Model.Pies)
{
<div>
<h2>@pie.Name</h2>
<h3>@pie.Price.ToString("c")</h3>
<h4>@pie.Category.CategoryName</h4>
</div>
}
</div>
</body>
</html>
public class PiesListViewModel
{
public IEnumerable<Pie> Pies { get; set; }
public string CurrentCategory { get; set; }
}
View Model
Demo
Creating the first view
Using a View Model
_Layout.cshtml
_ViewStart.cshtml
@using BethanysPieShop.Models
View Imports
Demo
Adding a layout template
Creating the ViewStart file
Adding the ViewImports file
Styling the View
Where We Need to Get
Using Library Manager (LibMan)
Older versions of Visual Studio: beware!
- Bower.json not supported anymore
- Adding packages manually
Demo
Adding client-side packages using
Library Manager
Add styles
Summary Building a complete page
- M
- V
- C