gustavnavar / Grid.Blazor

Grid component with CRUD for Blazor (client-side and server-side) and ASP.NET Core MVC
GNU Lesser General Public License v2.1
696 stars 134 forks source link

Two errors in version 5.0.3 #406

Closed lpyedge closed 5 months ago

lpyedge commented 9 months ago
  1. Excel export file is a 0kb file.
  2. The displayed language is based on the system language. The localization code scheme I use cannot display according to the language I set.

    • Version 5.0.3
    • OS: Windows 11 (23H2)
    • Browser Edge (v120)
    • .Net Version 6.0
lpyedge commented 9 months ago

I believe the Excel error was created by Commit 578d768. [GridBlazor/ExcelWriter.cs] Line173 -174 I downgraded to version 4.1.1, and now the Excel export works well.

gustavnavar commented 8 months ago

You are right. The issue about excel export is due to disposing the stream. I've published a new version (5.0.4) to fix it.

Referring the displayed language, I understand that the issue happens also in version 4.1.1, doesn't it? Are you using blazor-server or blazor-wasm?

lpyedge commented 8 months ago

You are right. The issue about excel export is due to disposing the stream. I've published a new version (5.0.4) to fix it.

Referring the displayed language, I understand that the issue happens also in version 4.1.1, doesn't it? Are you using blazor-server or blazor-wasm?

yes, the language displayed error is also happens in version 4.1.1 with blazor-server.

gustavnavar commented 8 months ago

You can look at this sample project https://gridblazor.azurewebsites.net/. It is implemented as a blazor-server project.

The source code is here https://github.com/gustavnavar/Grid.Blazor/tree/master/GridBlazorServerSide.

There is a blazor component that configures the language for each session:

@using System.Globalization
@using Microsoft.AspNetCore.Builder
@using Microsoft.Extensions.Options
@inject NavigationManager NavigationManager
@inject IOptions<RequestLocalizationOptions> LocOptions

<select class="form-control" value="@_language" @onchange="SetLanguage">
    @foreach (var culture in LocOptions.Value.SupportedUICultures)
    {
        <option value="@culture.Name">@culture.Name</option>
    }
</select>

@code {
    private string _language;

    protected override void OnInitialized()
    {
        _language = CultureInfo.CurrentCulture.Name;
    }

    private void SetLanguage(ChangeEventArgs e)
    {
        var culture = (string)e.Value;
        var uri = new Uri(NavigationManager.Uri)
            .GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped);
        var query = $"?culture={Uri.EscapeDataString(culture)}&" +
            $"redirectUri={Uri.EscapeDataString(uri)}";

        NavigationManager.NavigateTo("/Culture/SetCulture" + query, forceLoad: true);
    }
}

It calls to a web service that configures a cookie for the language:

using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc;

namespace GridBlazorServerSide.Controllers
{
    [Route("[controller]/[action]")]
    public class CultureController : Controller
    {
        public IActionResult SetCulture(string culture, string redirectUri)
        {
            if (culture != null)
            {
                HttpContext.Response.Cookies.Append(
                    CookieRequestCultureProvider.DefaultCookieName,
                    CookieRequestCultureProvider.MakeCookieValue(
                        new RequestCulture(culture)));
            }

            return LocalRedirect(redirectUri);
        }
    }
}