Skip to content

Commit e608708

Browse files
v9 Update: First MVC Series - 10 tutorials + app samples (#33192)
* v9 Update First MVC Series - 10 tutorials * Updated some screenshot links * Fix link * Fix code highlite and image link * Update aspnetcore/tutorials/first-mvc-app/start-mvc.md Co-authored-by: Tom Dykstra <tdykstra@microsoft.com> * Review fixes: remove finsihed app screenshots from start-mvc --------- Co-authored-by: Tom Dykstra <tdykstra@microsoft.com>
1 parent ab8cfa6 commit e608708

File tree

86 files changed

+793
-424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+793
-424
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!-- USED in RP and MVC tutorial for .NET 8 -->
2+
3+
## Add validation rules to the movie model
4+
5+
The DataAnnotations namespace provides a set of built-in validation attributes that are applied declaratively to a class or property. DataAnnotations also contains formatting attributes like `DataType` that help with formatting and don't provide any validation.
6+
7+
Update the `Movie` class to take advantage of the built-in validation attributes `Required`, `StringLength`, `RegularExpression`, `Range` and the `DataType` formatting attribute.
8+
9+
[!code-csharp[](~/tutorials/first-mvc-app/start-mvc/sample/MvcMovie80/Models/Movie.cs?name=snippet_Final&highlight=11-12,19-20,24-26,29-31)]
10+
11+
The validation attributes specify behavior that you want to enforce on the model properties they're applied to:
12+
13+
* The `Required` and `MinimumLength` attributes indicate that a property must have a value; but nothing prevents a user from entering white space to satisfy this validation.
14+
* The `RegularExpression` attribute is used to limit what characters can be input. In the preceding code, "Genre":
15+
16+
* Must only use letters.
17+
* The first letter is required to be uppercase. White spaces are allowed while numbers, and special
18+
characters are not allowed.
19+
20+
* The `RegularExpression` "Rating":
21+
22+
* Requires that the first character be an uppercase letter.
23+
* Allows special characters and numbers in subsequent spaces. "PG-13" is valid for a rating, but fails for a "Genre".
24+
25+
* The `Range` attribute constrains a value to within a specified range.
26+
* The `StringLength` attribute lets you set the maximum length of a string property, and optionally its minimum length.
27+
* Value types (such as `decimal`, `int`, `float`, `DateTime`) are inherently required and don't need the `[Required]` attribute.
28+
29+
Having validation rules automatically enforced by ASP.NET Core helps make your app more robust. It also ensures that you can't forget to validate something and inadvertently let bad data into the database.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!-- USED in RP and MVC tutorial for .NET 9 -->
2+
3+
## Add validation rules to the movie model
4+
5+
The DataAnnotations namespace provides a set of built-in validation attributes that are applied declaratively to a class or property. DataAnnotations also contains formatting attributes like `DataType` that help with formatting and don't provide any validation.
6+
7+
Update the `Movie` class to take advantage of the built-in validation attributes `Required`, `StringLength`, `RegularExpression`, `Range` and the `DataType` formatting attribute.
8+
9+
[!code-csharp[](~/tutorials/first-mvc-app/start-mvc/sample/MvcMovie90/Models/Movie.cs?name=snippet_Final&highlight=11-12,19-20,24-26,29-31)]
10+
11+
The validation attributes specify behavior that you want to enforce on the model properties they're applied to:
12+
13+
* The `Required` and `MinimumLength` attributes indicate that a property must have a value; but nothing prevents a user from entering white space to satisfy this validation.
14+
* The `RegularExpression` attribute is used to limit what characters can be input. In the preceding code, "Genre":
15+
16+
* Must only use letters.
17+
* The first letter is required to be uppercase. White spaces are allowed while numbers, and special
18+
characters are not allowed.
19+
20+
* The `RegularExpression` "Rating":
21+
22+
* Requires that the first character be an uppercase letter.
23+
* Allows special characters and numbers in subsequent spaces. "PG-13" is valid for a rating, but fails for a "Genre".
24+
25+
* The `Range` attribute constrains a value to within a specified range.
26+
* The `StringLength` attribute lets you set the maximum length of a string property, and optionally its minimum length.
27+
* Value types (such as `decimal`, `int`, `float`, `DateTime`) are inherently required and don't need the `[Required]` attribute.
28+
29+
Having validation rules automatically enforced by ASP.NET Core helps make your app more robust. It also ensures that you can't forget to validate something and inadvertently let bad data into the database.

aspnetcore/includes/vs-vsc-help.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# [Visual Studio](#tab/visual-studio)
2+
3+
## Visual Studio help
4+
5+
* [Learn to debug C# code using Visual Studio](/visualstudio/debugger/getting-started-with-the-debugger)
6+
* [Introduction to the Visual Studio IDE](/visualstudio/ide/visual-studio-ide)
7+
8+
# [Visual Studio Code](#tab/visual-studio-code)
9+
10+
## Visual Studio Code help
11+
12+
* [Getting started](https://code.visualstudio.com/docs)
13+
* [Debugging](https://code.visualstudio.com/docs/editor/debugging)
14+
* [Integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal)
15+
* [Keyboard shortcuts](https://code.visualstudio.com/docs/getstarted/keybindings#_keyboard-shortcuts-reference)
16+
17+
* [macOS keyboard shortcuts](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf)
18+
* [Linux keyboard shortcuts](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-linux.pdf)
19+
* [Windows keyboard shortcuts](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf)
20+
21+
---

aspnetcore/tutorials/first-mvc-app/adding-controller.md

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ title: Part 2, add a controller to an ASP.NET Core MVC app
33
author: wadepickett
44
description: Part 2 of tutorial series on ASP.NET Core MVC.
55
ms.author: wpickett
6-
ms.date: 02/15/2024
6+
ms.date: 07/24/2024
77
monikerRange: '>= aspnetcore-3.1'
88
uid: tutorials/first-mvc-app/adding-controller
9-
ms.custom: engagement-fy23
109
---
1110

1211
# Part 2, add a controller to an ASP.NET Core MVC app
@@ -45,11 +44,11 @@ These concepts are introduced and demonstrated in this tutorial series while bui
4544

4645
In **Solution Explorer**, right-click **Controllers > Add > Controller**.
4746

48-
![Solution Explorer, right click Controllers > Add > Controller](~/tutorials/first-mvc-app/adding-controller/_static/8/add-controller-VS22-17.8.0.png)
47+
![Solution Explorer, right click Controllers > Add > Controller](~/tutorials/first-mvc-app/adding-controller/_static/9/add-controller-VS22-17.11.0.png)
4948

5049
In the **Add New Scaffolded Item** dialog box, select **MVC Controller - Empty** > **Add**.
5150

52-
![Add MVC controller](~/tutorials/first-mvc-app/adding-controller/_static/8/add-scaffolded-item-controller-VS22-17.8.0.png)
51+
![Add MVC controller](~/tutorials/first-mvc-app/adding-controller/_static/9/add-scaffolded-item-controller-VS22-17.11.0.png)
5352

5453
In the **Add New Item - MvcMovie** dialog, enter *`HelloWorldController.cs`* and select **Add**.
5554

@@ -59,18 +58,6 @@ Select the **EXPLORER** icon and then control-click (right-click) **Controllers
5958

6059
![Contextual menu](~/tutorials/first-mvc-app-xplat/adding-controller/_static/new_fileVSC1.51.png)
6160

62-
# [Visual Studio for Mac](#tab/visual-studio-mac)
63-
64-
In **Solution Explorer**, control-click **Controllers** and select **Add > New File**.
65-
66-
![Contextual menu for adding a controller](~/tutorials/first-mvc-app-mac/adding-controller/_static/add_controller_MacVS22.png)
67-
68-
Select **ASP.NET Core** and **Controller Class**.
69-
70-
Name the controller **HelloWorldController**.
71-
72-
![Add MVC controller and name it](~/tutorials/first-mvc-app-mac/adding-controller/_static/ac_MacVS22.png)
73-
7461
---
7562

7663
Replace the contents of `Controllers/HelloWorldController.cs` with the following code:
@@ -95,7 +82,7 @@ Run the app without the debugger by pressing <kbd>Ctrl</kbd>+<kbd>F5</kbd> (Wind
9582

9683
Append `/HelloWorld` to the path in the address bar. The `Index` method returns a string.
9784

98-
![Browser window showing an app response of This is my default action](~/tutorials/first-mvc-app/adding-controller/_static/hell1.png)
85+
![Browser window showing an app response of This is my default action](~/tutorials/first-mvc-app/adding-controller/_static/9/hello1.png)
9986

10087
MVC invokes controller classes, and the action methods within them, depending on the incoming URL. The default [URL routing logic](xref:mvc/controllers/routing) used by MVC, uses a format like this to determine what code to invoke:
10188

@@ -115,7 +102,7 @@ Browse to: `https://localhost:{PORT}/HelloWorld/Welcome`. Replace `{PORT}` with
115102

116103
The `Welcome` method runs and returns the string `This is the Welcome action method...`. For this URL, the controller is `HelloWorld` and `Welcome` is the action method. You haven't used the `[Parameters]` part of the URL yet.
117104

118-
![Browser window showing an application response of This is the Welcome action method](~/tutorials/first-mvc-app/adding-controller/_static/welcome.png)
105+
![Browser window showing an application response of This is the Welcome action method](~/tutorials/first-mvc-app/adding-controller/_static/9/welcome.png)
119106

120107
Modify the code to pass some parameter information from the URL to the controller. For example, `/HelloWorld/Welcome?name=Rick&numtimes=4`.
121108

@@ -133,7 +120,7 @@ Run the app and browse to: `https://localhost:{PORT}/HelloWorld/Welcome?name=Ric
133120

134121
Try different values for `name` and `numtimes` in the URL. The MVC [model binding](xref:mvc/models/model-binding) system automatically maps the named parameters from the query string to parameters in the method. See [Model Binding](xref:mvc/models/model-binding) for more information.
135122

136-
![Browser window showing an application response of Hello Rick, NumTimes is\: 4](~/tutorials/first-mvc-app/adding-controller/_static/rick4.png)
123+
![Browser window showing an application response of Hello Rick, NumTimes is\: 4](~/tutorials/first-mvc-app/adding-controller/_static/9/rick4.png)
137124

138125
In the previous image:
139126

Loading
Loading
Loading

0 commit comments

Comments
 (0)