I'm trying to convert some lines of Razor code to C# code but can't seem to fix it.I got the following Razor code (the layout isn't important here so I just leave that out).
@page "/batch"
@layout ApmStandardLayout
@inherits TestApp.Pages.BatchComponent
@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 just copy pasting this into a C# editor (and removing all the '@'), I'm still getting some errors. The following errors occur:
- 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
I'm not an experienced C# programmer so help will be appreciated!
Thanks in advance.