Aggiunto helper estrazione querystring
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
@page "/TestComponenti"
|
||||
|
||||
@inject NavigationManager NavMan
|
||||
|
||||
<PageTitle>Test</PageTitle>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h1>Test Componenti custom</h1>
|
||||
@@ -15,7 +13,7 @@
|
||||
<div class="col-3">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3>Test Image</h3>
|
||||
Test Image
|
||||
</div>
|
||||
<div class="card-body py-1">
|
||||
<img src="_content/EgwCoreLib.Razor/images/LogoEgw.png" class="img-fluid" width="200" height="200" />
|
||||
@@ -48,25 +46,43 @@
|
||||
<div class="col-3">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Clipboard copy
|
||||
Input Speciali
|
||||
</div>
|
||||
<div class="card-body py-1">
|
||||
<small>Test copia clipboard, GUID (presudo)random</small>
|
||||
<CopyToClipboard Text="@textToCopy"></CopyToClipboard>
|
||||
<hr />
|
||||
<small>Input numerico con gestione cifre (es x double)</small>
|
||||
<NumInput CssClass="form-control" @bind-Value="@valDecimale"></NumInput>
|
||||
<div>
|
||||
<b>@valDecimale</b>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-3">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Number Input
|
||||
QueryString
|
||||
</div>
|
||||
<div class="card-body py-1">
|
||||
<small>Input numerico con gestione cifre (es x double)</small>
|
||||
<NumInput CssClass="form-control" @bind-Value="@valDecimale"></NumInput>
|
||||
<div>
|
||||
<b>@valDecimale</b>
|
||||
</div>
|
||||
|
||||
|
||||
Test valori QueryString
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">
|
||||
Query string <b>Nome</b>:
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
@qsNome
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
Query string <b>Intero</b>:
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
@qsIntero
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -81,4 +97,13 @@
|
||||
protected string textToCopy = $"{Guid.NewGuid()}";
|
||||
protected decimal valDecimale = 12345;
|
||||
|
||||
private string qsNome = "";
|
||||
private int qsIntero = 0;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
// base.OnInitialized();
|
||||
qsNome = NavMan.ExtractQueryStringByKey<string>("Nome");
|
||||
qsIntero = NavMan.ExtractQueryStringByKey<int>("Intero");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components" Version="6.0.14" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="6.0.14" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.1.1" />
|
||||
<PackageReference Include="ZXing.Net" Version="0.16.9" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EgwCoreLib.Razor
|
||||
{
|
||||
public static class NavigationManagerExtension
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Estensione metodo NavigationManager
|
||||
///
|
||||
/// https://code-maze.com/query-strings-blazor-webassembly/
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="navManager"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static T ExtractQueryStringByKey<T>(this NavigationManager navManager, string key)
|
||||
{
|
||||
var uri = navManager.ToAbsoluteUri(navManager.Uri);
|
||||
QueryHelpers.ParseQuery(uri.Query)
|
||||
.TryGetValue(key, out var queryValue);
|
||||
|
||||
if (typeof(T).Equals(typeof(int)))
|
||||
{
|
||||
int.TryParse(queryValue, out int result);
|
||||
return (T)(object)result;
|
||||
}
|
||||
|
||||
if (typeof(T).Equals(typeof(string)))
|
||||
return (T)(object)queryValue.ToString();
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user