├── .gitattributes
├── .gitignore
├── Blazor.Validation.Client
├── App.cshtml
├── Blazor.Validation.Client.csproj
├── Pages
│ ├── Counter.cshtml
│ ├── FetchData.cshtml
│ ├── Index.cshtml
│ ├── PersonValidation.cshtml
│ └── _ViewImports.cshtml
├── Program.cs
├── Properties
│ └── launchSettings.json
├── Shared
│ ├── MainLayout.cshtml
│ ├── NavMenu.cshtml
│ └── SurveyPrompt.cshtml
├── _ViewImports.cshtml
└── wwwroot
│ ├── css
│ ├── bootstrap
│ │ ├── bootstrap.min.css
│ │ └── bootstrap.min.css.map
│ ├── open-iconic
│ │ ├── FONT-LICENSE
│ │ ├── ICON-LICENSE
│ │ ├── README.md
│ │ └── font
│ │ │ ├── css
│ │ │ └── open-iconic-bootstrap.min.css
│ │ │ └── fonts
│ │ │ ├── open-iconic.eot
│ │ │ ├── open-iconic.otf
│ │ │ ├── open-iconic.svg
│ │ │ ├── open-iconic.ttf
│ │ │ └── open-iconic.woff
│ └── site.css
│ └── index.html
├── Blazor.Validation.Server
├── Blazor.Validation.Server.csproj
├── Controllers
│ └── SampleDataController.cs
├── Program.cs
├── Properties
│ └── launchSettings.json
└── Startup.cs
├── Blazor.Validation.Shared
├── Blazor.Validation.Shared.csproj
├── EnumerableExtensions.cs
├── Person.cs
└── WeatherForecast.cs
├── Blazor.Validation.sln
├── Blazor.Validation
├── Blazor.Validation.csproj
├── ExampleJsInterop.cs
├── Properties
│ └── launchSettings.json
├── ValidationError.cshtml
├── ValidationSummary.cshtml
└── content
│ ├── background.png
│ └── styles.css
├── Readme.md
├── Screenshots
└── BlazorValidation.PNG
└── global.json
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
--------------------------------------------------------------------------------
/Blazor.Validation.Client/App.cshtml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
--------------------------------------------------------------------------------
/Blazor.Validation.Client/Blazor.Validation.Client.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | Exe
6 | 7.3
7 |
8 |
9 | false
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | $(IncludeRazorContentInPack)
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/Blazor.Validation.Client/Pages/Counter.cshtml:
--------------------------------------------------------------------------------
1 | @page "/counter"
2 |
3 |
Counter
4 |
5 | Current count: @currentCount
6 |
7 | Click me
8 |
9 | @functions {
10 | int currentCount = 0;
11 |
12 | void IncrementCount()
13 | {
14 | currentCount++;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Blazor.Validation.Client/Pages/FetchData.cshtml:
--------------------------------------------------------------------------------
1 | @using Blazor.Validation.Shared
2 | @page "/fetchdata"
3 | @inject HttpClient Http
4 |
5 | Weather forecast
6 |
7 | This component demonstrates fetching data from the server.
8 |
9 | @if (forecasts == null)
10 | {
11 | Loading...
12 | }
13 | else
14 | {
15 |
16 |
17 |
18 | Date
19 | Temp. (C)
20 | Temp. (F)
21 | Summary
22 |
23 |
24 |
25 | @foreach (var forecast in forecasts)
26 | {
27 |
28 | @forecast.Date.ToShortDateString()
29 | @forecast.TemperatureC
30 | @forecast.TemperatureF
31 | @forecast.Summary
32 |
33 | }
34 |
35 |
36 | }
37 |
38 | @functions {
39 | WeatherForecast[] forecasts;
40 |
41 | protected override async Task OnInitAsync()
42 | {
43 | forecasts = await Http.GetJsonAsync("/api/SampleData/WeatherForecasts");
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Blazor.Validation.Client/Pages/Index.cshtml:
--------------------------------------------------------------------------------
1 | @page "/"
2 |
3 | Hello, world!
4 |
5 | Welcome to your new app.
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Blazor.Validation.Client/Pages/PersonValidation.cshtml:
--------------------------------------------------------------------------------
1 | @page "/validation"
2 | @addTagHelper *, Blazor.Validation
3 |
4 |
5 |
6 | First Name
7 |
8 |
9 |
10 |
11 | Last Name
12 |
13 |
14 |
15 |
16 | Age
17 |
18 |
19 |
20 |
21 | You should see two errors here. This is normal because of missing parameters.
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | You should see an error here. This is normal because of missing parameters.
30 |
31 |
32 |
33 | @functions {
34 | public Person Person { get; set; } = new Person { FirstName = "John", LastName = "Doe", Age = 32 };
35 | }
--------------------------------------------------------------------------------
/Blazor.Validation.Client/Pages/_ViewImports.cshtml:
--------------------------------------------------------------------------------
1 | @layout MainLayout
2 |
--------------------------------------------------------------------------------
/Blazor.Validation.Client/Program.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Blazor.Browser.Rendering;
2 | using Microsoft.AspNetCore.Blazor.Browser.Services;
3 | using Microsoft.Extensions.DependencyInjection;
4 | using Microsoft.Extensions.Logging;
5 | using Blazor.Extensions.Logging;
6 | using System;
7 |
8 | namespace Blazor.Validation.Client
9 | {
10 | public class Program
11 | {
12 | static void Main(string[] args)
13 | {
14 | var serviceProvider = new BrowserServiceProvider(services =>
15 | {
16 | // Add any custom services here
17 | services.AddLogging(builder => builder.AddBrowserConsole()
18 | .SetMinimumLevel(LogLevel.Information));
19 | });
20 |
21 | new BrowserRenderer(serviceProvider).AddComponent("app");
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Blazor.Validation.Client/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:53314/",
7 | "sslPort": 0
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "Blazor.Validation.Client": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "environmentVariables": {
22 | "ASPNETCORE_ENVIRONMENT": "Development"
23 | },
24 | "applicationUrl": "http://localhost:53315/"
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/Blazor.Validation.Client/Shared/MainLayout.cshtml:
--------------------------------------------------------------------------------
1 | @inherits BlazorLayoutComponent
2 |
3 |
6 |
7 |
8 |
11 |
12 |
13 | @Body
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Blazor.Validation.Client/Shared/NavMenu.cshtml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
32 |
33 | @functions {
34 | bool collapseNavMenu = true;
35 |
36 | void ToggleNavMenu()
37 | {
38 | collapseNavMenu = !collapseNavMenu;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Blazor.Validation.Client/Shared/SurveyPrompt.cshtml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
@Title
4 |
5 |
6 | Please take our
7 |
8 | brief survey
9 |
10 |
11 | and tell us what you think.
12 |
13 |
14 | @functions {
15 | [Parameter]
16 | string Title { get; set; } // Demonstrates how a parent component can supply parameters
17 | }
18 |
--------------------------------------------------------------------------------
/Blazor.Validation.Client/_ViewImports.cshtml:
--------------------------------------------------------------------------------
1 | @using System.Net.Http
2 | @using Microsoft.AspNetCore.Blazor
3 | @using Microsoft.AspNetCore.Blazor.Components
4 | @using Microsoft.AspNetCore.Blazor.Layouts
5 | @using Microsoft.AspNetCore.Blazor.Routing
6 | @using Microsoft.Extensions.Logging
7 |
8 | @using Blazor.Validation.Client
9 | @using Blazor.Validation.Client.Shared
10 | @using Blazor.Validation.Shared
11 |
--------------------------------------------------------------------------------
/Blazor.Validation.Client/wwwroot/css/open-iconic/FONT-LICENSE:
--------------------------------------------------------------------------------
1 | SIL OPEN FONT LICENSE Version 1.1
2 |
3 | Copyright (c) 2014 Waybury
4 |
5 | PREAMBLE
6 | The goals of the Open Font License (OFL) are to stimulate worldwide
7 | development of collaborative font projects, to support the font creation
8 | efforts of academic and linguistic communities, and to provide a free and
9 | open framework in which fonts may be shared and improved in partnership
10 | with others.
11 |
12 | The OFL allows the licensed fonts to be used, studied, modified and
13 | redistributed freely as long as they are not sold by themselves. The
14 | fonts, including any derivative works, can be bundled, embedded,
15 | redistributed and/or sold with any software provided that any reserved
16 | names are not used by derivative works. The fonts and derivatives,
17 | however, cannot be released under any other type of license. The
18 | requirement for fonts to remain under this license does not apply
19 | to any document created using the fonts or their derivatives.
20 |
21 | DEFINITIONS
22 | "Font Software" refers to the set of files released by the Copyright
23 | Holder(s) under this license and clearly marked as such. This may
24 | include source files, build scripts and documentation.
25 |
26 | "Reserved Font Name" refers to any names specified as such after the
27 | copyright statement(s).
28 |
29 | "Original Version" refers to the collection of Font Software components as
30 | distributed by the Copyright Holder(s).
31 |
32 | "Modified Version" refers to any derivative made by adding to, deleting,
33 | or substituting -- in part or in whole -- any of the components of the
34 | Original Version, by changing formats or by porting the Font Software to a
35 | new environment.
36 |
37 | "Author" refers to any designer, engineer, programmer, technical
38 | writer or other person who contributed to the Font Software.
39 |
40 | PERMISSION & CONDITIONS
41 | Permission is hereby granted, free of charge, to any person obtaining
42 | a copy of the Font Software, to use, study, copy, merge, embed, modify,
43 | redistribute, and sell modified and unmodified copies of the Font
44 | Software, subject to the following conditions:
45 |
46 | 1) Neither the Font Software nor any of its individual components,
47 | in Original or Modified Versions, may be sold by itself.
48 |
49 | 2) Original or Modified Versions of the Font Software may be bundled,
50 | redistributed and/or sold with any software, provided that each copy
51 | contains the above copyright notice and this license. These can be
52 | included either as stand-alone text files, human-readable headers or
53 | in the appropriate machine-readable metadata fields within text or
54 | binary files as long as those fields can be easily viewed by the user.
55 |
56 | 3) No Modified Version of the Font Software may use the Reserved Font
57 | Name(s) unless explicit written permission is granted by the corresponding
58 | Copyright Holder. This restriction only applies to the primary font name as
59 | presented to the users.
60 |
61 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
62 | Software shall not be used to promote, endorse or advertise any
63 | Modified Version, except to acknowledge the contribution(s) of the
64 | Copyright Holder(s) and the Author(s) or with their explicit written
65 | permission.
66 |
67 | 5) The Font Software, modified or unmodified, in part or in whole,
68 | must be distributed entirely under this license, and must not be
69 | distributed under any other license. The requirement for fonts to
70 | remain under this license does not apply to any document created
71 | using the Font Software.
72 |
73 | TERMINATION
74 | This license becomes null and void if any of the above conditions are
75 | not met.
76 |
77 | DISCLAIMER
78 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
79 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
80 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
81 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
82 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
83 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
84 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
85 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
86 | OTHER DEALINGS IN THE FONT SOFTWARE.
87 |
--------------------------------------------------------------------------------
/Blazor.Validation.Client/wwwroot/css/open-iconic/ICON-LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Waybury
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
--------------------------------------------------------------------------------
/Blazor.Validation.Client/wwwroot/css/open-iconic/README.md:
--------------------------------------------------------------------------------
1 | [Open Iconic v1.1.1](http://useiconic.com/open)
2 | ===========
3 |
4 | ### Open Iconic is the open source sibling of [Iconic](http://useiconic.com). It is a hyper-legible collection of 223 icons with a tiny footprint—ready to use with Bootstrap and Foundation. [View the collection](http://useiconic.com/open#icons)
5 |
6 |
7 |
8 | ## What's in Open Iconic?
9 |
10 | * 223 icons designed to be legible down to 8 pixels
11 | * Super-light SVG files - 61.8 for the entire set
12 | * SVG sprite—the modern replacement for icon fonts
13 | * Webfont (EOT, OTF, SVG, TTF, WOFF), PNG and WebP formats
14 | * Webfont stylesheets (including versions for Bootstrap and Foundation) in CSS, LESS, SCSS and Stylus formats
15 | * PNG and WebP raster images in 8px, 16px, 24px, 32px, 48px and 64px.
16 |
17 |
18 | ## Getting Started
19 |
20 | #### For code samples and everything else you need to get started with Open Iconic, check out our [Icons](http://useiconic.com/open#icons) and [Reference](http://useiconic.com/open#reference) sections.
21 |
22 | ### General Usage
23 |
24 | #### Using Open Iconic's SVGs
25 |
26 | We like SVGs and we think they're the way to display icons on the web. Since Open Iconic are just basic SVGs, we suggest you display them like you would any other image (don't forget the `alt` attribute).
27 |
28 | ```
29 |
30 | ```
31 |
32 | #### Using Open Iconic's SVG Sprite
33 |
34 | Open Iconic also comes in a SVG sprite which allows you to display all the icons in the set with a single request. It's like an icon font, without being a hack.
35 |
36 | Adding an icon from an SVG sprite is a little different than what you're used to, but it's still a piece of cake. *Tip: To make your icons easily style able, we suggest adding a general class to the* `` *tag and a unique class name for each different icon in the* `` *tag.*
37 |
38 | ```
39 |
40 |
41 |
42 | ```
43 |
44 | Sizing icons only needs basic CSS. All the icons are in a square format, so just set the `` tag with equal width and height dimensions.
45 |
46 | ```
47 | .icon {
48 | width: 16px;
49 | height: 16px;
50 | }
51 | ```
52 |
53 | Coloring icons is even easier. All you need to do is set the `fill` rule on the `` tag.
54 |
55 | ```
56 | .icon-account-login {
57 | fill: #f00;
58 | }
59 | ```
60 |
61 | To learn more about SVG Sprites, read [Chris Coyier's guide](http://css-tricks.com/svg-sprites-use-better-icon-fonts/).
62 |
63 | #### Using Open Iconic's Icon Font...
64 |
65 |
66 | ##### …with Bootstrap
67 |
68 | You can find our Bootstrap stylesheets in `font/css/open-iconic-bootstrap.{css, less, scss, styl}`
69 |
70 |
71 | ```
72 |
73 | ```
74 |
75 |
76 | ```
77 |
78 | ```
79 |
80 | ##### …with Foundation
81 |
82 | You can find our Foundation stylesheets in `font/css/open-iconic-foundation.{css, less, scss, styl}`
83 |
84 | ```
85 |
86 | ```
87 |
88 |
89 | ```
90 |
91 | ```
92 |
93 | ##### …on its own
94 |
95 | You can find our default stylesheets in `font/css/open-iconic.{css, less, scss, styl}`
96 |
97 | ```
98 |
99 | ```
100 |
101 | ```
102 |
103 | ```
104 |
105 |
106 | ## License
107 |
108 | ### Icons
109 |
110 | All code (including SVG markup) is under the [MIT License](http://opensource.org/licenses/MIT).
111 |
112 | ### Fonts
113 |
114 | All fonts are under the [SIL Licensed](http://scripts.sil.org/cms/scripts/page.php?item_id=OFL_web).
115 |
--------------------------------------------------------------------------------
/Blazor.Validation.Client/wwwroot/css/open-iconic/font/css/open-iconic-bootstrap.min.css:
--------------------------------------------------------------------------------
1 | @font-face{font-family:Icons;src:url(../fonts/open-iconic.eot);src:url(../fonts/open-iconic.eot?#iconic-sm) format('embedded-opentype'),url(../fonts/open-iconic.woff) format('woff'),url(../fonts/open-iconic.ttf) format('truetype'),url(../fonts/open-iconic.otf) format('opentype'),url(../fonts/open-iconic.svg#iconic-sm) format('svg');font-weight:400;font-style:normal}.oi{position:relative;top:1px;display:inline-block;speak:none;font-family:Icons;font-style:normal;font-weight:400;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.oi:empty:before{width:1em;text-align:center;box-sizing:content-box}.oi.oi-align-center:before{text-align:center}.oi.oi-align-left:before{text-align:left}.oi.oi-align-right:before{text-align:right}.oi.oi-flip-horizontal:before{-webkit-transform:scale(-1,1);-ms-transform:scale(-1,1);transform:scale(-1,1)}.oi.oi-flip-vertical:before{-webkit-transform:scale(1,-1);-ms-transform:scale(-1,1);transform:scale(1,-1)}.oi.oi-flip-horizontal-vertical:before{-webkit-transform:scale(-1,-1);-ms-transform:scale(-1,1);transform:scale(-1,-1)}.oi-account-login:before{content:'\e000'}.oi-account-logout:before{content:'\e001'}.oi-action-redo:before{content:'\e002'}.oi-action-undo:before{content:'\e003'}.oi-align-center:before{content:'\e004'}.oi-align-left:before{content:'\e005'}.oi-align-right:before{content:'\e006'}.oi-aperture:before{content:'\e007'}.oi-arrow-bottom:before{content:'\e008'}.oi-arrow-circle-bottom:before{content:'\e009'}.oi-arrow-circle-left:before{content:'\e00a'}.oi-arrow-circle-right:before{content:'\e00b'}.oi-arrow-circle-top:before{content:'\e00c'}.oi-arrow-left:before{content:'\e00d'}.oi-arrow-right:before{content:'\e00e'}.oi-arrow-thick-bottom:before{content:'\e00f'}.oi-arrow-thick-left:before{content:'\e010'}.oi-arrow-thick-right:before{content:'\e011'}.oi-arrow-thick-top:before{content:'\e012'}.oi-arrow-top:before{content:'\e013'}.oi-audio-spectrum:before{content:'\e014'}.oi-audio:before{content:'\e015'}.oi-badge:before{content:'\e016'}.oi-ban:before{content:'\e017'}.oi-bar-chart:before{content:'\e018'}.oi-basket:before{content:'\e019'}.oi-battery-empty:before{content:'\e01a'}.oi-battery-full:before{content:'\e01b'}.oi-beaker:before{content:'\e01c'}.oi-bell:before{content:'\e01d'}.oi-bluetooth:before{content:'\e01e'}.oi-bold:before{content:'\e01f'}.oi-bolt:before{content:'\e020'}.oi-book:before{content:'\e021'}.oi-bookmark:before{content:'\e022'}.oi-box:before{content:'\e023'}.oi-briefcase:before{content:'\e024'}.oi-british-pound:before{content:'\e025'}.oi-browser:before{content:'\e026'}.oi-brush:before{content:'\e027'}.oi-bug:before{content:'\e028'}.oi-bullhorn:before{content:'\e029'}.oi-calculator:before{content:'\e02a'}.oi-calendar:before{content:'\e02b'}.oi-camera-slr:before{content:'\e02c'}.oi-caret-bottom:before{content:'\e02d'}.oi-caret-left:before{content:'\e02e'}.oi-caret-right:before{content:'\e02f'}.oi-caret-top:before{content:'\e030'}.oi-cart:before{content:'\e031'}.oi-chat:before{content:'\e032'}.oi-check:before{content:'\e033'}.oi-chevron-bottom:before{content:'\e034'}.oi-chevron-left:before{content:'\e035'}.oi-chevron-right:before{content:'\e036'}.oi-chevron-top:before{content:'\e037'}.oi-circle-check:before{content:'\e038'}.oi-circle-x:before{content:'\e039'}.oi-clipboard:before{content:'\e03a'}.oi-clock:before{content:'\e03b'}.oi-cloud-download:before{content:'\e03c'}.oi-cloud-upload:before{content:'\e03d'}.oi-cloud:before{content:'\e03e'}.oi-cloudy:before{content:'\e03f'}.oi-code:before{content:'\e040'}.oi-cog:before{content:'\e041'}.oi-collapse-down:before{content:'\e042'}.oi-collapse-left:before{content:'\e043'}.oi-collapse-right:before{content:'\e044'}.oi-collapse-up:before{content:'\e045'}.oi-command:before{content:'\e046'}.oi-comment-square:before{content:'\e047'}.oi-compass:before{content:'\e048'}.oi-contrast:before{content:'\e049'}.oi-copywriting:before{content:'\e04a'}.oi-credit-card:before{content:'\e04b'}.oi-crop:before{content:'\e04c'}.oi-dashboard:before{content:'\e04d'}.oi-data-transfer-download:before{content:'\e04e'}.oi-data-transfer-upload:before{content:'\e04f'}.oi-delete:before{content:'\e050'}.oi-dial:before{content:'\e051'}.oi-document:before{content:'\e052'}.oi-dollar:before{content:'\e053'}.oi-double-quote-sans-left:before{content:'\e054'}.oi-double-quote-sans-right:before{content:'\e055'}.oi-double-quote-serif-left:before{content:'\e056'}.oi-double-quote-serif-right:before{content:'\e057'}.oi-droplet:before{content:'\e058'}.oi-eject:before{content:'\e059'}.oi-elevator:before{content:'\e05a'}.oi-ellipses:before{content:'\e05b'}.oi-envelope-closed:before{content:'\e05c'}.oi-envelope-open:before{content:'\e05d'}.oi-euro:before{content:'\e05e'}.oi-excerpt:before{content:'\e05f'}.oi-expand-down:before{content:'\e060'}.oi-expand-left:before{content:'\e061'}.oi-expand-right:before{content:'\e062'}.oi-expand-up:before{content:'\e063'}.oi-external-link:before{content:'\e064'}.oi-eye:before{content:'\e065'}.oi-eyedropper:before{content:'\e066'}.oi-file:before{content:'\e067'}.oi-fire:before{content:'\e068'}.oi-flag:before{content:'\e069'}.oi-flash:before{content:'\e06a'}.oi-folder:before{content:'\e06b'}.oi-fork:before{content:'\e06c'}.oi-fullscreen-enter:before{content:'\e06d'}.oi-fullscreen-exit:before{content:'\e06e'}.oi-globe:before{content:'\e06f'}.oi-graph:before{content:'\e070'}.oi-grid-four-up:before{content:'\e071'}.oi-grid-three-up:before{content:'\e072'}.oi-grid-two-up:before{content:'\e073'}.oi-hard-drive:before{content:'\e074'}.oi-header:before{content:'\e075'}.oi-headphones:before{content:'\e076'}.oi-heart:before{content:'\e077'}.oi-home:before{content:'\e078'}.oi-image:before{content:'\e079'}.oi-inbox:before{content:'\e07a'}.oi-infinity:before{content:'\e07b'}.oi-info:before{content:'\e07c'}.oi-italic:before{content:'\e07d'}.oi-justify-center:before{content:'\e07e'}.oi-justify-left:before{content:'\e07f'}.oi-justify-right:before{content:'\e080'}.oi-key:before{content:'\e081'}.oi-laptop:before{content:'\e082'}.oi-layers:before{content:'\e083'}.oi-lightbulb:before{content:'\e084'}.oi-link-broken:before{content:'\e085'}.oi-link-intact:before{content:'\e086'}.oi-list-rich:before{content:'\e087'}.oi-list:before{content:'\e088'}.oi-location:before{content:'\e089'}.oi-lock-locked:before{content:'\e08a'}.oi-lock-unlocked:before{content:'\e08b'}.oi-loop-circular:before{content:'\e08c'}.oi-loop-square:before{content:'\e08d'}.oi-loop:before{content:'\e08e'}.oi-magnifying-glass:before{content:'\e08f'}.oi-map-marker:before{content:'\e090'}.oi-map:before{content:'\e091'}.oi-media-pause:before{content:'\e092'}.oi-media-play:before{content:'\e093'}.oi-media-record:before{content:'\e094'}.oi-media-skip-backward:before{content:'\e095'}.oi-media-skip-forward:before{content:'\e096'}.oi-media-step-backward:before{content:'\e097'}.oi-media-step-forward:before{content:'\e098'}.oi-media-stop:before{content:'\e099'}.oi-medical-cross:before{content:'\e09a'}.oi-menu:before{content:'\e09b'}.oi-microphone:before{content:'\e09c'}.oi-minus:before{content:'\e09d'}.oi-monitor:before{content:'\e09e'}.oi-moon:before{content:'\e09f'}.oi-move:before{content:'\e0a0'}.oi-musical-note:before{content:'\e0a1'}.oi-paperclip:before{content:'\e0a2'}.oi-pencil:before{content:'\e0a3'}.oi-people:before{content:'\e0a4'}.oi-person:before{content:'\e0a5'}.oi-phone:before{content:'\e0a6'}.oi-pie-chart:before{content:'\e0a7'}.oi-pin:before{content:'\e0a8'}.oi-play-circle:before{content:'\e0a9'}.oi-plus:before{content:'\e0aa'}.oi-power-standby:before{content:'\e0ab'}.oi-print:before{content:'\e0ac'}.oi-project:before{content:'\e0ad'}.oi-pulse:before{content:'\e0ae'}.oi-puzzle-piece:before{content:'\e0af'}.oi-question-mark:before{content:'\e0b0'}.oi-rain:before{content:'\e0b1'}.oi-random:before{content:'\e0b2'}.oi-reload:before{content:'\e0b3'}.oi-resize-both:before{content:'\e0b4'}.oi-resize-height:before{content:'\e0b5'}.oi-resize-width:before{content:'\e0b6'}.oi-rss-alt:before{content:'\e0b7'}.oi-rss:before{content:'\e0b8'}.oi-script:before{content:'\e0b9'}.oi-share-boxed:before{content:'\e0ba'}.oi-share:before{content:'\e0bb'}.oi-shield:before{content:'\e0bc'}.oi-signal:before{content:'\e0bd'}.oi-signpost:before{content:'\e0be'}.oi-sort-ascending:before{content:'\e0bf'}.oi-sort-descending:before{content:'\e0c0'}.oi-spreadsheet:before{content:'\e0c1'}.oi-star:before{content:'\e0c2'}.oi-sun:before{content:'\e0c3'}.oi-tablet:before{content:'\e0c4'}.oi-tag:before{content:'\e0c5'}.oi-tags:before{content:'\e0c6'}.oi-target:before{content:'\e0c7'}.oi-task:before{content:'\e0c8'}.oi-terminal:before{content:'\e0c9'}.oi-text:before{content:'\e0ca'}.oi-thumb-down:before{content:'\e0cb'}.oi-thumb-up:before{content:'\e0cc'}.oi-timer:before{content:'\e0cd'}.oi-transfer:before{content:'\e0ce'}.oi-trash:before{content:'\e0cf'}.oi-underline:before{content:'\e0d0'}.oi-vertical-align-bottom:before{content:'\e0d1'}.oi-vertical-align-center:before{content:'\e0d2'}.oi-vertical-align-top:before{content:'\e0d3'}.oi-video:before{content:'\e0d4'}.oi-volume-high:before{content:'\e0d5'}.oi-volume-low:before{content:'\e0d6'}.oi-volume-off:before{content:'\e0d7'}.oi-warning:before{content:'\e0d8'}.oi-wifi:before{content:'\e0d9'}.oi-wrench:before{content:'\e0da'}.oi-x:before{content:'\e0db'}.oi-yen:before{content:'\e0dc'}.oi-zoom-in:before{content:'\e0dd'}.oi-zoom-out:before{content:'\e0de'}
--------------------------------------------------------------------------------
/Blazor.Validation.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PeterHimschoot/Blazor.Validation/1263bb1202784483e2730219e58922725715eaec/Blazor.Validation.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.eot
--------------------------------------------------------------------------------
/Blazor.Validation.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.otf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PeterHimschoot/Blazor.Validation/1263bb1202784483e2730219e58922725715eaec/Blazor.Validation.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.otf
--------------------------------------------------------------------------------
/Blazor.Validation.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 | Created by FontForge 20120731 at Tue Jul 1 20:39:22 2014
9 | By P.J. Onori
10 | Created by P.J. Onori with FontForge 2.0 (http://fontforge.sf.net)
11 |
12 |
13 |
14 |
27 |
28 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
45 |
47 |
49 |
51 |
53 |
55 |
57 |
59 |
61 |
63 |
65 |
67 |
69 |
71 |
74 |
76 |
79 |
81 |
84 |
86 |
88 |
91 |
93 |
95 |
98 |
100 |
102 |
104 |
106 |
109 |
112 |
115 |
117 |
121 |
123 |
125 |
127 |
130 |
132 |
134 |
136 |
138 |
141 |
143 |
145 |
147 |
149 |
151 |
153 |
155 |
157 |
159 |
162 |
165 |
167 |
169 |
172 |
174 |
177 |
179 |
181 |
183 |
185 |
189 |
191 |
194 |
196 |
198 |
200 |
202 |
205 |
207 |
209 |
211 |
213 |
215 |
218 |
220 |
222 |
224 |
226 |
228 |
230 |
232 |
234 |
236 |
238 |
241 |
243 |
245 |
247 |
249 |
251 |
253 |
256 |
259 |
261 |
263 |
265 |
267 |
269 |
272 |
274 |
276 |
280 |
282 |
285 |
287 |
289 |
292 |
295 |
298 |
300 |
302 |
304 |
306 |
309 |
312 |
314 |
316 |
318 |
320 |
322 |
324 |
326 |
330 |
334 |
338 |
340 |
343 |
345 |
347 |
349 |
351 |
353 |
355 |
358 |
360 |
363 |
365 |
367 |
369 |
371 |
373 |
375 |
377 |
379 |
381 |
383 |
386 |
388 |
390 |
392 |
394 |
396 |
399 |
401 |
404 |
406 |
408 |
410 |
412 |
414 |
416 |
419 |
421 |
423 |
425 |
428 |
431 |
435 |
438 |
440 |
442 |
444 |
446 |
448 |
451 |
453 |
455 |
457 |
460 |
462 |
464 |
466 |
468 |
471 |
473 |
477 |
479 |
481 |
483 |
486 |
488 |
490 |
492 |
494 |
496 |
499 |
501 |
504 |
506 |
509 |
512 |
515 |
517 |
520 |
522 |
524 |
526 |
529 |
532 |
534 |
536 |
539 |
542 |
543 |
544 |
--------------------------------------------------------------------------------
/Blazor.Validation.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PeterHimschoot/Blazor.Validation/1263bb1202784483e2730219e58922725715eaec/Blazor.Validation.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf
--------------------------------------------------------------------------------
/Blazor.Validation.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PeterHimschoot/Blazor.Validation/1263bb1202784483e2730219e58922725715eaec/Blazor.Validation.Client/wwwroot/css/open-iconic/font/fonts/open-iconic.woff
--------------------------------------------------------------------------------
/Blazor.Validation.Client/wwwroot/css/site.css:
--------------------------------------------------------------------------------
1 | @import url('open-iconic/font/css/open-iconic-bootstrap.min.css');
2 |
3 | html, body {
4 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
5 | }
6 |
7 | app {
8 | position: relative;
9 | display: flex;
10 | flex-direction: column;
11 | }
12 |
13 | .top-row {
14 | height: 3.5rem;
15 | display: flex;
16 | align-items: center;
17 | }
18 |
19 | .main {
20 | flex: 1;
21 | }
22 |
23 | .main .top-row {
24 | background-color: #e6e6e6;
25 | border-bottom: 1px solid #d6d5d5;
26 | }
27 |
28 | .sidebar {
29 | background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
30 | }
31 |
32 | .sidebar .top-row {
33 | background-color: rgba(0,0,0,0.4);
34 | }
35 |
36 | .sidebar .navbar-brand {
37 | font-size: 1.1rem;
38 | }
39 |
40 | .sidebar .oi {
41 | width: 2rem;
42 | font-size: 1.1rem;
43 | vertical-align: text-top;
44 | top: -2px;
45 | }
46 |
47 | .nav-item {
48 | font-size: 0.9rem;
49 | padding-bottom: 0.5rem;
50 | }
51 |
52 | .nav-item:first-of-type {
53 | padding-top: 1rem;
54 | }
55 |
56 | .nav-item:last-of-type {
57 | padding-bottom: 1rem;
58 | }
59 |
60 | .nav-item a {
61 | color: #d7d7d7;
62 | border-radius: 4px;
63 | height: 3rem;
64 | display: flex;
65 | align-items: center;
66 | line-height: 3rem;
67 | }
68 |
69 | .nav-item a.active {
70 | background-color: rgba(255,255,255,0.25);
71 | color: white;
72 | }
73 |
74 | .nav-item a:hover {
75 | background-color: rgba(255,255,255,0.1);
76 | color: white;
77 | }
78 |
79 | .content {
80 | padding-top: 1.1rem;
81 | }
82 |
83 | .navbar-toggler {
84 | background-color: rgba(255, 255, 255, 0.1);
85 | }
86 |
87 | @media (max-width: 767.98px) {
88 | .main .top-row {
89 | display: none;
90 | }
91 | }
92 |
93 | @media (min-width: 768px) {
94 | app {
95 | flex-direction: row;
96 | }
97 |
98 | .sidebar {
99 | width: 250px;
100 | height: 100vh;
101 | position: sticky;
102 | top: 0;
103 | }
104 |
105 | .main .top-row {
106 | position: sticky;
107 | top: 0;
108 | }
109 |
110 | .main > div {
111 | padding-left: 2rem !important;
112 | padding-right: 1.5rem !important;
113 | }
114 |
115 | .navbar-toggler {
116 | display: none;
117 | }
118 |
119 | .sidebar .collapse {
120 | /* Never collapse the sidebar for wide screens */
121 | display: block;
122 | }
123 |
124 | .validationerror > ul > li {
125 | color:red;
126 | }
127 |
128 | .validationsummary > ul > li {
129 | color:darkred;
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/Blazor.Validation.Client/wwwroot/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Blazor.Validation
7 |
8 |
9 |
10 |
11 |
12 | Loading...
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Blazor.Validation.Server/Blazor.Validation.Server.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 | 7.3
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/Blazor.Validation.Server/Controllers/SampleDataController.cs:
--------------------------------------------------------------------------------
1 | using Blazor.Validation.Shared;
2 | using Microsoft.AspNetCore.Mvc;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 |
8 | namespace Blazor.Validation.Server.Controllers
9 | {
10 | [Route("api/[controller]")]
11 | public class SampleDataController : Controller
12 | {
13 | private static string[] Summaries = new[]
14 | {
15 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
16 | };
17 |
18 | [HttpGet("[action]")]
19 | public IEnumerable WeatherForecasts()
20 | {
21 | var rng = new Random();
22 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast
23 | {
24 | Date = DateTime.Now.AddDays(index),
25 | TemperatureC = rng.Next(-20, 55),
26 | Summary = Summaries[rng.Next(Summaries.Length)]
27 | });
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Blazor.Validation.Server/Program.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using Microsoft.AspNetCore;
5 | using Microsoft.AspNetCore.Hosting;
6 | using Microsoft.Extensions.Configuration;
7 |
8 | namespace Blazor.Validation.Server
9 | {
10 | public class Program
11 | {
12 | public static void Main(string[] args)
13 | {
14 | BuildWebHost(args).Run();
15 | }
16 |
17 | public static IWebHost BuildWebHost(string[] args) =>
18 | WebHost.CreateDefaultBuilder(args)
19 | .UseConfiguration(new ConfigurationBuilder()
20 | .AddCommandLine(args)
21 | .Build())
22 | .UseStartup()
23 | .Build();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Blazor.Validation.Server/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:53310/",
7 | "sslPort": 0
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "Blazor.Validation.Server": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "environmentVariables": {
22 | "ASPNETCORE_ENVIRONMENT": "Development"
23 | },
24 | "applicationUrl": "http://localhost:53311/"
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/Blazor.Validation.Server/Startup.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using Microsoft.AspNetCore.Blazor.Server;
5 | using Microsoft.AspNetCore.Builder;
6 | using Microsoft.AspNetCore.Hosting;
7 | using Microsoft.AspNetCore.ResponseCompression;
8 | using Microsoft.Extensions.DependencyInjection;
9 | using Newtonsoft.Json.Serialization;
10 | using System.Linq;
11 | using System.Net.Mime;
12 |
13 | namespace Blazor.Validation.Server
14 | {
15 | public class Startup
16 | {
17 | // This method gets called by the runtime. Use this method to add services to the container.
18 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
19 | public void ConfigureServices(IServiceCollection services)
20 | {
21 | services.AddMvc().AddJsonOptions(options =>
22 | {
23 | options.SerializerSettings.ContractResolver = new DefaultContractResolver();
24 | });
25 |
26 | services.AddResponseCompression(options =>
27 | {
28 | options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[]
29 | {
30 | MediaTypeNames.Application.Octet,
31 | WasmMediaTypeNames.Application.Wasm,
32 | });
33 | });
34 | }
35 |
36 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
37 | public void Configure(IApplicationBuilder app, IHostingEnvironment env)
38 | {
39 | app.UseResponseCompression();
40 |
41 | if (env.IsDevelopment())
42 | {
43 | app.UseDeveloperExceptionPage();
44 | }
45 |
46 | app.UseMvc(routes =>
47 | {
48 | routes.MapRoute(name: "default", template: "{controller}/{action}/{id?}");
49 | });
50 |
51 | app.UseBlazor();
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Blazor.Validation.Shared/Blazor.Validation.Shared.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | 7.3
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Blazor.Validation.Shared/EnumerableExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace Blazor.Validation.Shared
7 | {
8 | public static class EnumerableExtensions
9 | {
10 | public static bool Any(this IEnumerable e) => e.GetEnumerator().MoveNext() == true;
11 |
12 | public static T FirstOrDefault(this IEnumerable e)
13 | {
14 | var enumerator = e.GetEnumerator();
15 | if( enumerator.MoveNext() )
16 | {
17 | return (T)enumerator.Current;
18 | }
19 | return default(T);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Blazor.Validation.Shared/Person.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.ComponentModel;
5 | using System.Text;
6 |
7 | namespace Blazor.Validation.Shared
8 | {
9 | public class Person : IDataErrorInfo, INotifyDataErrorInfo
10 | {
11 | public string FirstName { get; set; }
12 |
13 | public string LastName { get; set; }
14 |
15 | public string FullName => $"{FirstName} {LastName}";
16 |
17 | public int Age { get; set; }
18 |
19 | const int minAge = 18;
20 |
21 | public string this[string property]
22 | {
23 | get
24 | {
25 | return GetErrors(property).FirstOrDefault();
26 | }
27 | }
28 |
29 | public string Error
30 | {
31 | get
32 | {
33 | return null;
34 | }
35 | }
36 |
37 | public bool HasErrors => GetErrors(null).Any();
38 |
39 | public event EventHandler ErrorsChanged;
40 |
41 | public IEnumerable GetErrors(string property)
42 | {
43 | if (property == null || property == nameof(this.FirstName))
44 | {
45 | if (string.IsNullOrEmpty(this.FirstName))
46 | {
47 | yield return $"{nameof(FirstName)} is mandatory";
48 | }
49 | if( this.FirstName.Length < 2 )
50 | {
51 | yield return $"{nameof(FirstName)} '{this.FirstName}' is too short.";
52 | }
53 | if( this.FirstName == "Q")
54 | {
55 | yield return $"{nameof(FirstName)} 'Q' is reserved for extra-dimensional beings!";
56 | }
57 | }
58 | if (property == null || property == nameof(this.LastName))
59 | {
60 | if (string.IsNullOrEmpty(this.LastName))
61 | {
62 | yield return $"{nameof(LastName)} is mandatory";
63 | }
64 | if (this.LastName == "Doe")
65 | {
66 | yield return $"{nameof(LastName)} cannot be 'Doe'";
67 | }
68 | }
69 | if (property == null || property == nameof(this.Age))
70 | {
71 | if (Age < minAge)
72 | {
73 | yield return $"{nameof(Age)} should be at least {minAge}";
74 | }
75 | }
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/Blazor.Validation.Shared/WeatherForecast.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Blazor.Validation.Shared
6 | {
7 | public class WeatherForecast
8 | {
9 | public DateTime Date { get; set; }
10 | public int TemperatureC { get; set; }
11 | public string Summary { get; set; }
12 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Blazor.Validation.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27703.2000
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Validation.Server", "Blazor.Validation.Server\Blazor.Validation.Server.csproj", "{E7793DEE-AAE4-4CB7-86D9-9FAF1D8325B6}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Validation.Client", "Blazor.Validation.Client\Blazor.Validation.Client.csproj", "{A6633B73-294A-457B-9026-986F7AFDE392}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Validation.Shared", "Blazor.Validation.Shared\Blazor.Validation.Shared.csproj", "{BE48BD1D-948C-4A44-8F08-ECFDD01764A3}"
11 | EndProject
12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Validation", "Blazor.Validation\Blazor.Validation.csproj", "{8A759480-AD4D-40AF-9B35-482E12516DD6}"
13 | EndProject
14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{09A9DF56-D5CE-4917-A872-E506823BE9D7}"
15 | ProjectSection(SolutionItems) = preProject
16 | Readme.md = Readme.md
17 | EndProjectSection
18 | EndProject
19 | Global
20 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
21 | Debug|Any CPU = Debug|Any CPU
22 | Release|Any CPU = Release|Any CPU
23 | EndGlobalSection
24 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
25 | {E7793DEE-AAE4-4CB7-86D9-9FAF1D8325B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26 | {E7793DEE-AAE4-4CB7-86D9-9FAF1D8325B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
27 | {E7793DEE-AAE4-4CB7-86D9-9FAF1D8325B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
28 | {E7793DEE-AAE4-4CB7-86D9-9FAF1D8325B6}.Release|Any CPU.Build.0 = Release|Any CPU
29 | {A6633B73-294A-457B-9026-986F7AFDE392}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30 | {A6633B73-294A-457B-9026-986F7AFDE392}.Debug|Any CPU.Build.0 = Debug|Any CPU
31 | {A6633B73-294A-457B-9026-986F7AFDE392}.Release|Any CPU.ActiveCfg = Release|Any CPU
32 | {A6633B73-294A-457B-9026-986F7AFDE392}.Release|Any CPU.Build.0 = Release|Any CPU
33 | {BE48BD1D-948C-4A44-8F08-ECFDD01764A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34 | {BE48BD1D-948C-4A44-8F08-ECFDD01764A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
35 | {BE48BD1D-948C-4A44-8F08-ECFDD01764A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
36 | {BE48BD1D-948C-4A44-8F08-ECFDD01764A3}.Release|Any CPU.Build.0 = Release|Any CPU
37 | {8A759480-AD4D-40AF-9B35-482E12516DD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38 | {8A759480-AD4D-40AF-9B35-482E12516DD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
39 | {8A759480-AD4D-40AF-9B35-482E12516DD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
40 | {8A759480-AD4D-40AF-9B35-482E12516DD6}.Release|Any CPU.Build.0 = Release|Any CPU
41 | EndGlobalSection
42 | GlobalSection(SolutionProperties) = preSolution
43 | HideSolutionNode = FALSE
44 | EndGlobalSection
45 | GlobalSection(ExtensibilityGlobals) = postSolution
46 | SolutionGuid = {0E5C735A-4ED0-498B-8118-940C3F072920}
47 | EndGlobalSection
48 | EndGlobal
49 |
--------------------------------------------------------------------------------
/Blazor.Validation/Blazor.Validation.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | Library
6 | true
7 | false
8 | 7.3
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | $(IncludeRazorContentInPack)
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/Blazor.Validation/ExampleJsInterop.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.AspNetCore.Blazor.Browser.Interop;
3 |
4 | namespace Blazor.Validation
5 | {
6 | public class ExampleJsInterop
7 | {
8 | public static string Prompt(string message)
9 | {
10 | return RegisteredFunction.Invoke(
11 | "Blazor.Validation.ExampleJsInterop.Prompt",
12 | message);
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Blazor.Validation/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:53501/",
7 | "sslPort": 0
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "Blazor.Validation": {
19 | "commandName": "Project"
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/Blazor.Validation/ValidationError.cshtml:
--------------------------------------------------------------------------------
1 | @using System.ComponentModel
2 | @using Microsoft.AspNetCore.Blazor.Components
3 |
4 | @if (Errors.Any())
5 | {
6 |
7 |
8 | @foreach (var error in Errors)
9 | {
10 | @error
11 | }
12 |
13 |
14 | }
15 |
16 | @functions {
17 |
18 | [Parameter]
19 | protected object Subject { get; set; }
20 |
21 | [Parameter]
22 | protected string Property { get; set; }
23 |
24 | public IEnumerable Errors
25 | {
26 | get
27 | {
28 | switch (Subject)
29 | {
30 | case null:
31 | yield return $"{nameof(Subject)} has not been set!";
32 | yield break;
33 | case INotifyDataErrorInfo ine:
34 | if( Property == null )
35 | {
36 | yield return $"{nameof(Property)} has not been set!";
37 | yield break;
38 | }
39 | foreach (var err in ine.GetErrors(Property))
40 | {
41 | yield return (string)err;
42 | }
43 | break;
44 | case IDataErrorInfo ide:
45 | if( Property == null )
46 | {
47 | yield return $"{nameof(Property)} has not been set!";
48 | yield break;
49 | }
50 | string error = ide[Property];
51 | if (error != null)
52 | {
53 | yield return error;
54 | }
55 | else
56 | {
57 | yield break;
58 | }
59 | break;
60 | }
61 | }
62 | }
63 | }
--------------------------------------------------------------------------------
/Blazor.Validation/ValidationSummary.cshtml:
--------------------------------------------------------------------------------
1 | @using System.ComponentModel
2 | @using Microsoft.AspNetCore.Blazor.Components
3 | @using System.Reflection
4 |
5 | @if (Errors.Any())
6 | {
7 |
8 |
9 | @foreach (var error in Errors)
10 | {
11 | @error
12 | }
13 |
14 |
15 | }
16 |
17 | @functions {
18 |
19 | [Parameter]
20 | protected object Subject { get; set; }
21 |
22 | public IEnumerable Errors
23 | {
24 | get
25 | {
26 | string error = null;
27 | switch (Subject)
28 | {
29 | case null:
30 | yield return $"{nameof(Subject)} has not been set!";
31 | yield break;
32 | case INotifyDataErrorInfo ine:
33 | foreach (var property in PropertyNames)
34 | {
35 | foreach (string err in ine.GetErrors(property))
36 | {
37 | yield return err;
38 | }
39 | }
40 | break;
41 | case IDataErrorInfo ide:
42 | // IDataErrorInfo.Error: what is wrong with this object.
43 | error = ide.Error;
44 | if( error != null )
45 | {
46 | yield return error;
47 | }
48 | // IDataErrorInfo[property]: what is wrong with this object's property
49 | foreach (var property in PropertyNames)
50 | {
51 | error = ide[property];
52 | if (error != null)
53 | {
54 | yield return ide[property];
55 | }
56 | }
57 | break;
58 | }
59 | }
60 | }
61 |
62 | private List propertyNames = null;
63 |
64 | private List PropertyNames
65 | => propertyNames ?? (propertyNames = GetSubjectPropertyNames().ToList());
66 |
67 | private IEnumerable GetSubjectPropertyNames()
68 | {
69 | return Subject.GetType()
70 | .GetProperties(BindingFlags.Public | BindingFlags.Instance)
71 | .Select(pi => pi.Name);
72 | }
73 | }
--------------------------------------------------------------------------------
/Blazor.Validation/content/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PeterHimschoot/Blazor.Validation/1263bb1202784483e2730219e58922725715eaec/Blazor.Validation/content/background.png
--------------------------------------------------------------------------------
/Blazor.Validation/content/styles.css:
--------------------------------------------------------------------------------
1 | /*
2 | This file is to show how CSS and other static resources (such as images) can be
3 | used from a library project/package.
4 | */
5 |
6 | .my-component {
7 | border: 2px dashed red;
8 | padding: 1em;
9 | margin: 1em 0;
10 | background-image: url('background.png');
11 | }
12 |
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
1 | # Blazor Validation
2 |
3 | Blazor is a framework that allows you to build rich web pages and SPAs using .NET standard libraries and C#.
4 |
5 | > At the time of writing Blazor is experimental!
6 |
7 | In this blog post I want to talk about forms validation with blazor. Since there is no official validation framework yet in blazor I've decided to build it myself. Here is an example of validation in action:
8 |
9 | 
10 |
11 | So how does this work? My blazor component looks like this:
12 |
13 | ``` cshtml
14 | @page "/validation"
15 | @addTagHelper *, Blazor.Validation
16 |
17 |
34 |
35 |
36 |
37 |
38 |
39 | @functions {
40 | public Person Person { get; set; } = new Person { FirstName = "John", LastName = "Doe", Age = 32 };
41 | }
42 | ```
43 |
44 | As you can see I'm using two components: `ValidationError` and `ValidationSummary`. The first one is used to display specific problems with a `Subject`'s `Property`, and the second one gives you an overview of all validation errors on the `Subject`.
45 |
46 | ## Validating entities with .NET
47 |
48 | .NET has a couple of built-in mechanisms for validation, and I support the two most important: `IDataErrorInfo` and `INotifyDataErrorInfo`.
49 |
50 | `System.ComponentModel.IDataErrorInfo` has been around since .NET 1.0, and allows you to return an error for each property, and for the whole object:
51 |
52 | > `System.ComponentModel` contains classes and interfaces which are available throughout most of .NET, including `INotifyPropertyChanged` and is in my opinion one of the most important namespaces!
53 |
54 | ``` csharp
55 | // Summary:
56 | // Provides the functionality to offer custom error information that a user interface
57 | // can bind to.
58 | [DefaultMember("Item")]
59 | public interface IDataErrorInfo
60 | {
61 | //
62 | // Summary:
63 | // Gets the error message for the property with the given name.
64 | //
65 | // Parameters:
66 | // columnName:
67 | // The name of the property whose error message to get.
68 | //
69 | // Returns:
70 | // The error message for the property. The default is an empty string ("").
71 | string this[string columnName] { get; }
72 |
73 | //
74 | // Summary:
75 | // Gets an error message indicating what is wrong with this object.
76 | //
77 | // Returns:
78 | // An error message indicating what is wrong with this object. The default is an
79 | // empty string ("").
80 | string Error { get; }
81 | }
82 | ```
83 |
84 | The biggest drawback of `IDataErrorInfo` is that you can only return one error per property, but on the other hand this interface is supported by WinForms, WPF, ASP.NET Mvc, etc...
85 |
86 | `INotifyDataErrorInfo` is a more modern version of `IDataErrorInfo`:
87 |
88 | ``` csharp
89 | // Summary:
90 | // Defines members that data entity classes can implement to provide custom synchronous
91 | // and asynchronous validation support.
92 | public interface INotifyDataErrorInfo
93 | {
94 | //
95 | // Summary:
96 | // Gets a value that indicates whether the entity has validation errors.
97 | //
98 | // Returns:
99 | // true if the entity currently has validation errors; otherwise, false.
100 | bool HasErrors { get; }
101 |
102 | //
103 | // Summary:
104 | // Occurs when the validation errors have changed for a property or for the entire
105 | // entity.
106 | event EventHandler ErrorsChanged;
107 |
108 | //
109 | // Summary:
110 | // Gets the validation errors for a specified property or for the entire entity.
111 | //
112 | // Parameters:
113 | // propertyName:
114 | // The name of the property to retrieve validation errors for; or null or System.String.Empty,
115 | // to retrieve entity-level errors.
116 | //
117 | // Returns:
118 | // The validation errors for the property or entity.
119 | IEnumerable GetErrors(string propertyName);
120 | }
121 | ```
122 |
123 | This interface allows multiple errors per property.
124 |
125 | Here is my implementation of a simple `Person` class supporting both interfaces:
126 |
127 | ``` csharp
128 | public class Person : IDataErrorInfo, INotifyDataErrorInfo
129 | {
130 | public string FirstName { get; set; }
131 |
132 | public string LastName { get; set; }
133 |
134 | public string FullName => $"{FirstName} {LastName}";
135 |
136 | public int Age { get; set; }
137 |
138 | const int minAge = 18;
139 |
140 | public string this[string property]
141 | {
142 | get
143 | {
144 | return GetErrors(property).FirstOrDefault();
145 | }
146 | }
147 |
148 | public string Error
149 | {
150 | get
151 | {
152 | return null;
153 | }
154 | }
155 |
156 | public bool HasErrors => GetErrors(null).Any();
157 |
158 | public event EventHandler ErrorsChanged;
159 |
160 | public IEnumerable GetErrors(string property)
161 | {
162 | if (property == null || property == nameof(this.FirstName))
163 | {
164 | if (string.IsNullOrEmpty(this.FirstName))
165 | {
166 | yield return $"{nameof(FirstName)} is mandatory";
167 | }
168 | if( this.FirstName.Length < 2 )
169 | {
170 | yield return $"{nameof(FirstName)} '{this.FirstName}' is too short.";
171 | }
172 | if( this.FirstName == "Q")
173 | {
174 | yield return $"{nameof(FirstName)} 'Q' is reserved for extra-dimensional beings!";
175 | }
176 | }
177 | if (property == null || property == nameof(this.LastName))
178 | {
179 | if (string.IsNullOrEmpty(this.LastName))
180 | {
181 | yield return $"{nameof(LastName)} is mandatory";
182 | }
183 | if (this.LastName == "Doe")
184 | {
185 | yield return $"{nameof(LastName)} cannot be 'Doe'";
186 | }
187 | }
188 | if (property == null || property == nameof(this.Age))
189 | {
190 | if (Age < minAge)
191 | {
192 | yield return $"{nameof(Age)} should be at least {minAge}";
193 | }
194 | }
195 | }
196 | }
197 | ```
198 |
199 | ## Onto ValidationError
200 |
201 | Let's look at the `ValidationError` Blazor component:
202 |
203 | ``` csharp
204 | @using System.ComponentModel
205 | @using Microsoft.AspNetCore.Blazor.Components
206 |
207 | @if (Errors.Any())
208 | {
209 |
210 |
211 | @foreach (var error in Errors)
212 | {
213 | @error
214 | }
215 |
216 |
217 | }
218 |
219 | @functions {
220 |
221 | [Parameter]
222 | protected object Subject { get; set; }
223 |
224 | [Parameter]
225 | protected string Property { get; set; }
226 |
227 | public IEnumerable Errors
228 | {
229 | get
230 | {
231 | switch (Subject)
232 | {
233 | case null:
234 | yield return $"{nameof(Subject)} has not been set!";
235 | yield break;
236 | case INotifyDataErrorInfo ine:
237 | if( Property == null )
238 | {
239 | yield return $"{nameof(Property)} has not been set!";
240 | yield break;
241 | }
242 | foreach (var err in ine.GetErrors(Property))
243 | {
244 | yield return (string)err;
245 | }
246 | break;
247 | case IDataErrorInfo ide:
248 | if( Property == null )
249 | {
250 | yield return $"{nameof(Property)} has not been set!";
251 | yield break;
252 | }
253 | string error = ide[Property];
254 | if (error != null)
255 | {
256 | yield return error;
257 | }
258 | else
259 | {
260 | yield break;
261 | }
262 | break;
263 | }
264 | }
265 | }
266 | }
267 | ```
268 |
269 | As you can see, it is pretty simple. First I check if there are any error, and then I use a `div` with nested `ul` and one `li` per error.
270 |
271 | The `div` has a class `validationerror` associated with it so you can style it:
272 |
273 | ``` css
274 | .validationerror > ul > li {
275 | color:red;
276 | }
277 | ```
278 |
279 | The `Errors` property returns an `IEnumerable` of errors, which checks the `Subject` for one of the interfaces using the new C# 7 pattern matching syntax:
280 |
281 | ``` csharp
282 | switch (Subject)
283 | {
284 | case null:
285 | yield return $"{nameof(Subject)} has not been set!";
286 | yield break;
287 | case INotifyDataErrorInfo ine:
288 | ...
289 | case IDataErrorInfo ide:
290 | ...
291 | }
292 | ```
293 |
294 | You can learn more about C# 7 pattern mathing (here)[https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7#pattern-matching]:
295 |
296 | If `Subject` has not been set I return a validation error to the developer! Otherwise I read the validation errors through the interface and return them using C#'s `yield` syntax.
297 |
298 | Again, if `yield` is not familiar, read [this](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/yield).
299 |
300 | ## ValidationSummary
301 |
302 | The `ValidationSummary` components works in very much the same way:
303 |
304 | ``` cshtml
305 | @using System.ComponentModel
306 | @using Microsoft.AspNetCore.Blazor.Components
307 | @using System.Reflection
308 |
309 | @if (Errors.Any())
310 | {
311 |
312 |
313 | @foreach (var error in Errors)
314 | {
315 | @error
316 | }
317 |
318 |
319 | }
320 |
321 | @functions {
322 |
323 | [Parameter]
324 | protected object Subject { get; set; }
325 |
326 | public IEnumerable Errors
327 | {
328 | get
329 | {
330 | string error = null;
331 | switch (Subject)
332 | {
333 | case null:
334 | yield return $"{nameof(Subject)} has not been set!";
335 | yield break;
336 | case INotifyDataErrorInfo ine:
337 | foreach (var property in PropertyNames)
338 | {
339 | foreach (string err in ine.GetErrors(property))
340 | {
341 | yield return err;
342 | }
343 | }
344 | break;
345 | case IDataErrorInfo ide:
346 | // IDataErrorInfo.Error: what is wrong with this object.
347 | error = ide.Error;
348 | if( error != null )
349 | {
350 | yield return error;
351 | }
352 | // IDataErrorInfo[property]: what is wrong with this object's property
353 | foreach (var property in PropertyNames)
354 | {
355 | error = ide[property];
356 | if (error != null)
357 | {
358 | yield return ide[property];
359 | }
360 | }
361 | break;
362 | }
363 | }
364 | }
365 |
366 | private List propertyNames = null;
367 |
368 | private List PropertyNames
369 | => propertyNames ?? (propertyNames = GetSubjectPropertyNames().ToList());
370 |
371 | private IEnumerable GetSubjectPropertyNames()
372 | {
373 | return Subject.GetType()
374 | .GetProperties(BindingFlags.Public | BindingFlags.Instance)
375 | .Select(pi => pi.Name);
376 | }
377 | }
378 | ```
379 |
380 | The big difference here is that I need to show all property's errors, and for this I use a little reflection:
381 |
382 | ``` csharp
383 | private List propertyNames = null;
384 |
385 | private List PropertyNames
386 | => propertyNames ?? (propertyNames = GetSubjectPropertyNames().ToList());
387 |
388 | private IEnumerable GetSubjectPropertyNames()
389 | {
390 | return Subject.GetType()
391 | .GetProperties(BindingFlags.Public | BindingFlags.Instance)
392 | .Select(pi => pi.Name);
393 | }
394 | ```
395 |
396 | Because **reflection is slow** I cache all properties so I only have to get them once.
397 |
398 | ## Summary
399 |
400 | That's it! Because Blazor allows me to use the same constructs as normal .net, I can use familiar interfaces and techniques.
401 |
402 | The full project is available on (my GitHub)[https://github.com/PeterHimschoot/Blazor.Validation].
403 |
404 |
405 |
406 |
407 |
--------------------------------------------------------------------------------
/Screenshots/BlazorValidation.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PeterHimschoot/Blazor.Validation/1263bb1202784483e2730219e58922725715eaec/Screenshots/BlazorValidation.PNG
--------------------------------------------------------------------------------
/global.json:
--------------------------------------------------------------------------------
1 | {
2 | "sdk": {
3 | "version": "2.1.300-preview2-008533"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------