Skip to content

[blazor] url enconding sometimes not working with UriHelper.NavigateTo #10887

@ichensky

Description

@ichensky
  1. Create blazor page(just replace counter page from basic vs blazor template):
@page "/counter"
@page "/counter/{search}"
@inject IUriHelper UriHelper

<p>
This search has problems with encoding:<br>
<input type="search" 
       value="@Search" 
       placeholder="enter here: `тест`"
       oninput="@(e=> UriHelper.NavigateTo($"/counter/{e.Value.ToString()}") )" />
</p>
<p>
    <input type="search" 
           value="@Search" 
           placeholder="enter here: `тест`"
       oninput="@(e=> UriHelper.NavigateTo(e.Value.ToString()) )" />
</p>

<p>Search: @Search</p>
@functions {
    [Parameter]
    public string Search { get; set; } = string.Empty;
}
  1. Write any not latin text, for ex. тест in the second input field,
    page will be navigated to the /тест (in the browser url)
    and in the input
    you'll see 'тест'
  2. Write any not latin text, for ex. тест in the first input field,
    page will be navigated to the /counter/тест (in_ the browser url)
    and in the input
    you'll see %D1%82%D0%B5%D1%81%D1%82 instead of тест

To solve this issue, needed, somewhere for ex. in basic method of blazor component OnParametersSet
call decode method for all params, like:

 protected override void OnParametersSet() {
        base.OnParametersSet();
        // do the same for all params
        Search = System.Net.WebUtility.UrlDecode(Search); 
    }

Metadata

Metadata

Labels

area-blazorIncludes: Blazor, Razor Components

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions