fix: 修复 Blazor 模式无法打开问题

This commit is contained in:
Argo-Cloud 2021-03-12 01:47:17 +08:00
parent 6a3b006cc1
commit 80f5c1be1f
3 changed files with 16 additions and 5 deletions

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Components; using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms; using Microsoft.AspNetCore.Components.Forms;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
@ -64,14 +65,18 @@ namespace Bootstrap.Admin.Pages.Components
public string GetDisplayName() public string GetDisplayName()
{ {
var ret = ""; var ret = "";
if (_fieldIdentifier == null) _fieldIdentifier = FieldIdentifier.Create(ValueExpression); if (_fieldIdentifier == null)
{
_fieldIdentifier = FieldIdentifier.Create(ValueExpression);
}
if (DisplayNamesExtensions.TryGetValue((_fieldIdentifier.Value.Model.GetType(), _fieldIdentifier.Value.FieldName), out var s)) if (DisplayNamesExtensions.TryGetValue((_fieldIdentifier.Value.Model.GetType(), _fieldIdentifier.Value.FieldName), out var s))
{ {
ret = s; ret = s;
} }
if (string.IsNullOrEmpty(ret)) if (string.IsNullOrEmpty(ret))
{ {
ret = _fieldIdentifier?.GetDisplayName() ?? ""; ret = _fieldIdentifier.HasValue ? FieldIdentifierExtensions.GetDisplayName(_fieldIdentifier.Value) : "";
} }
return ret; return ret;
} }
@ -81,7 +86,11 @@ namespace Bootstrap.Admin.Pages.Components
/// </summary> /// </summary>
public string GetFieldName() public string GetFieldName()
{ {
if (_fieldIdentifier == null) _fieldIdentifier = FieldIdentifier.Create(ValueExpression); if (_fieldIdentifier == null)
{
_fieldIdentifier = FieldIdentifier.Create(ValueExpression);
}
return _fieldIdentifier?.FieldName ?? ""; return _fieldIdentifier?.FieldName ?? "";
} }
} }

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Components; using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms; using Microsoft.AspNetCore.Components.Forms;
using Microsoft.JSInterop; using Microsoft.JSInterop;
using System; using System;

View File

@ -92,6 +92,7 @@ namespace Bootstrap.Admin
if (Enviroment.IsDevelopment()) options.DetailedErrors = true; if (Enviroment.IsDevelopment()) options.DetailedErrors = true;
}); });
services.AddDisplayNames(); services.AddDisplayNames();
services.AddBootstrapBlazor();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.