在Url - Blazor中写入变量



我想把我在URL的文本框中设置的变量,在我的域名后面。这样的:

https://localhost: 44305/变量。

我已经看到你可以在URL中传递一个变量,但不知道如何在URL后动态地写一个变量,例如文本框。

如何将URL输入参数值传递到Blazor页面?

<input @bind="ErrorCode"/>
<!--With the Input i fetch the a data from a database (searching for the right dataset with the input-ErrorCode).

The data i fetched from database is shown e.g. in a table-->
<br/>
<br/>
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
</tr>
</table>

<!--My Problem now is, when the person who searched for an ErrorCode, 
wants to send the URL to another person, the other person only gets the page, without an input value.-->

我想我明白了。我不太确定这是不是最好的解决方案,但它确实有效。如果我说错了,请纠正我。:)

@using Microsoft.AspNetCore.WebUtilities
@inject NavigationManager navigationManager
<form>
<input @bind="ErrorCode"/>
</form>
@code
{
System.Uri uri;
protected override void OnInitialized()
{
uri = navigationManager.ToAbsoluteUri(navigationManager.Uri);
if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("ErrorCode", out var errorCodeValue))
{
ErrorCode = errorCodeValue;
}
}
}

最新更新