-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23c1fc4
commit d0870b3
Showing
11 changed files
with
198 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlazorExamples.Models; | ||
|
||
public class PersonModel | ||
{ | ||
public string FirstName { get; set; } | ||
public string LastName { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@page "/auth-required" | ||
@attribute [Authorize] | ||
|
||
<h3>Auth Required</h3> | ||
|
||
<p class="alert alert-success" role="alert">Hooray, when you can see this your successfully authorized!</p> | ||
|
||
@code { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@page "/partitial-auth" | ||
|
||
<h3>Partitial Auth</h3> | ||
<p>With Login you see the Power Counter!</p> | ||
<AuthorizeView> | ||
<Authorized> | ||
<h4>Power Counter</h4> | ||
<Counter IncrementBy="500" startingValue="1000"/> | ||
</Authorized> | ||
<NotAuthorized> | ||
<h4>Normal Counter</h4> | ||
<Counter /> | ||
</NotAuthorized> | ||
</AuthorizeView> | ||
|
||
@code { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
@page "/basic-forms" | ||
@using BlazorExamples.Models; | ||
|
||
<h3>User Form</h3> | ||
<p> | ||
@formResults | ||
</p> | ||
<p> | ||
First Name: @person.FirstName | ||
</p> | ||
<p> | ||
Last Name: @person.LastName | ||
</p> | ||
|
||
<EditForm Model="@person" OnValidSubmit="HandleValidSubmit"> | ||
<InputText id="firstName" @bind-Value="person.FirstName" /> | ||
<InputText id="lastName" @bind-Value="person.LastName" /> | ||
<button class="btn btn-primary" type="submit">Submit</button> | ||
</EditForm> | ||
|
||
|
||
@code { | ||
private PersonModel person = new PersonModel(); | ||
private string formResults = ""; | ||
|
||
private void HandleValidSubmit() | ||
{ | ||
formResults = $"{person.FirstName} {person.LastName} was just created."; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
@page "/upload" | ||
@inject ILogger<Index> Logger | ||
|
||
<h3>Upload Files</h3> | ||
|
||
<p> | ||
<label> | ||
Max file size in MB: | ||
<input type="number" @bind="maxFileSize" /> | ||
</label> | ||
</p> | ||
|
||
<p> | ||
<label> | ||
Max allowed files: | ||
<input type="number" @bind="maxAllowedFiles" /> | ||
</label> | ||
</p> | ||
|
||
<p> | ||
<label> | ||
Upload up to @maxAllowedFiles of up to @maxFileSize MB: | ||
<InputFile OnChange="@LoadFiles" multiple /> | ||
</label> | ||
</p> | ||
|
||
@if (isLoading) | ||
{ | ||
<p>Uploading...</p> | ||
} | ||
else | ||
{ | ||
@foreach (var file in loadedFiles) | ||
{ | ||
<ul> | ||
<li>Name: @file.Name</li> | ||
<li>Last modified: @file.LastModified.ToString()</li> | ||
<li>Size (bytes): @file.Size</li> | ||
<li>Content type: @file.ContentType</li> | ||
</ul> | ||
<br /> | ||
} | ||
} | ||
|
||
@code { | ||
private List<IBrowserFile> loadedFiles = new(); | ||
private long maxFileSize = 1; | ||
private int maxAllowedFiles = 3; | ||
private bool isLoading; | ||
|
||
private async Task LoadFiles(InputFileChangeEventArgs e) | ||
{ | ||
isLoading = true; | ||
loadedFiles.Clear(); | ||
|
||
foreach (var file in e.GetMultipleFiles(maxAllowedFiles)) | ||
{ | ||
if (file.Size > (maxFileSize * 1024 * 1024)) | ||
{ | ||
continue; | ||
} | ||
|
||
try | ||
{ | ||
loadedFiles.Add(file); | ||
|
||
var path = Path.Combine(@"C:\Temp", | ||
file.Name); | ||
|
||
await using FileStream fs = new(path, FileMode.Create); | ||
await file.OpenReadStream(maxFileSize * 1024 * 1024).CopyToAsync(fs); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Logger.LogError("File: {Filename} Error: {Error}", | ||
file.Name, ex.Message); | ||
} | ||
} | ||
|
||
isLoading = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.