From f056ca49e227480e927861184d87ebf5d4aec8bf Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Fri, 25 Feb 2022 11:45:01 -0500 Subject: [PATCH] Update for 25-02-22 11:45 --- tech/asp.net.wiki | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tech/asp.net.wiki b/tech/asp.net.wiki index 5d95f91..e2481f6 100644 --- a/tech/asp.net.wiki +++ b/tech/asp.net.wiki @@ -20,6 +20,41 @@ mysite.com/XYZ/Create. This applies for all methods in the Controller class following signature `public IActionResult MyCustomMethod()`. These usually end with a `return View()`. These methods are called Actions or Action Methods. +== Models == + +Models are objects in asp.net that represent entries in database tables, or +data to be processed by the backend of the application. + +=== Model validation === + +Member values in a model can be validated via validation attributes. These +attributes are + +* Required +* StringLength(x) +* DataType(type) +* Display(Name = "Some display name") +* Range(0,100) +* ValidateNever +* CreditCard +* EmailAddress +* Phone +* Url +* etc... + +All of the validation attributes are placed in square brackets one lines above +the member values of the model. For example, + +{{{ +[Phone] +[Required] +public string phoneNumber { get; set; } + }}} + +All validation attributes can also be passed an argument of name `ErrorMessage` +of type string, and will be displayed on the webpage when the value is not +given. + == Controllers == === Return types === @@ -47,6 +82,8 @@ A cshtml block may be created using a `@{}` block. Here C# can be placed, however it is always ran by an interpretter at runtime, and is therefore not recomended often. +=== ActionLink === + === Passing data to views === A view can take paramaters, primarily a single object, via passing it to the