text
stringlengths 0
13.4k
|
|---|
part of MVC and covers many of the concepts you'd use in a larger
|
application.
|
In this book, you'll build a to-do app that lets the user add items to their
|
to-do list and check them off once complete. More specifically, you'll be
|
creating:
|
A web application server (sometimes called the "backend") using
|
ASP.NET Core, C#, and the MVC pattern
|
A database to store the user's to-do items using the SQLite database
|
engine and a system called Entity Framework Core
|
Web pages and an interface that the user will interact with via their
|
browser, using HTML, CSS, and JavaScript (called the "frontend")
|
A login form and security checks so each user's to-do list is kept
|
private
|
Sound good? Let's built it! If you haven't already created a new ASP.NET
|
Core project using dotnet new mvc , follow the steps in the previous
|
chapter. You should be able to build and run the project and see the
|
default welcome screen.
|
21
|
Create a controller
|
Create a controller
|
There are already a few controllers in the project's Controllers directory,
|
including the HomeController that renders the default welcome screen
|
you see when you visit http://localhost:5000 . You can ignore these
|
controllers for now.
|
Create a new controller for the to-do list functionality, called
|
TodoController , and add the following code:
|
Controllers/TodoController.cs
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Threading.Tasks;
|
using Microsoft.AspNetCore.Mvc;
|
namespace AspNetCoreTodo.Controllers
|
{
|
public class TodoController : Controller
|
{
|
// Actions go here
|
}
|
}
|
Routes that are handled by controllers are called actions, and are
|
represented by methods in the controller class. For example, the
|
HomeController includes three action methods ( Index , About , and
|
Contact ) which are mapped by ASP.NET Core to these route URLs:
|
localhost:5000/Home -> Index()
|
localhost:5000/Home/About -> About()
|
localhost:5000/Home/Contact -> Contact()
|
22
|
Create a controller
|
There are a number of conventions (common patterns) used by ASP.NET
|
Core, such as the pattern that FooController becomes /Foo , and the
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.