Greetings!
Maybe not really Radzen related but I hope you can help me out. I need to move some lines of code from a .razor file to a .razor.cs. file but I'm not sure on how to do that. I created the following code in the .razor file (note that the layout isn't important here so I just leave that out):
@page "/batch"
@layout ApmStandardLayout
@inherits TestApp.Pages.BatchComponent
@using Radzen
@using Radzen.Blazor
@using TestApp.Models.HmiDb
@using Microsoft.AspNetCore.Identity;
@using TestApp.Models
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize]
@using System.Threading
@using System.Threading.Tasks;
@using Microsoft.AspNetCore.SignalR.Client;
@inject NavigationManager NavigationManager
@code { private TagData.TagData tagData = new TagData.TagData();
private HubConnection hubConnection;
protected override async Task OnInitializedAsync()
{
hubConnection = new HubConnectionBuilder()
.WithUrl(NavigationManager.ToAbsoluteUri("/tagservice"))
.Build();
hubConnection.On<TagData.TagData>("TagData", (data) =>
{
tagData = data;
plctext_BatchID = data.plctext_BatchID.ToString("#.00");
plctext_Data_CNC3_Products_Actual = data.plctext_Data_CNC3_Products_Actual.ToString("#.00");
plctext_Data_CNC3_Destination_Actual = data.plctext_Data_CNC3_Destination_Actual.ToString("#.00");
plctext_Data_CNC4_Products_Actual = data.plctext_Data_CNC4_Products_Actual.ToString("#.00");
plctext_Data_CNC4_Destination_Actual = data.plctext_Data_CNC3_Destination_Actual.ToString("#.00");
plctext_ProgressPercentage = data.plctext_ProgressPercentage.ToString("#.00");
RecipeNameActual = data.RecipeNameActual;
RecipeLengthActual = data.RecipeLengthActual.ToString(".00");
RecipeDepthActual = data.RecipeDepthActual.ToString("#.00");
RecipeBasketActual = data.RecipeBasketActual.ToString("#.00");
StateHasChanged();
});
await hubConnection.StartAsync();
} }
When I'm trying to move this to the .razor.cs file I'm getting two errors:
- Error CS0111 Type 'BatchComponent' already defines a member called 'OnInitializedAsync' with the same parameter types TestApp
- Error CS0103 The name 'NavigationManager' does not exist in the current context TestApp
The first error has something to do with OnInitializedAsync() being used already. I've found the code that uses this but I can't find a way around this to use the same function again.
protected override async System.Threading.Tasks.Task OnInitializedAsync()
{
await Security.InitializeAsync(AuthenticationStateProvider);
if (!Security.IsAuthenticated())
{
UriHelper.NavigateTo("Login", true);
}
else
{
await Load();
}
}
The second error is probably a wrong injection error. I've tried to convert @inject Navigationmanager NavigationManager
to C# code but everything I do is wrong.
I'd hope any of you can help me with my problems because I really need to make these lines of code move to the .razor.cs file.
Thanks in advance!