USMC6072
USMC6072

Reputation: 668

Blazor server-side not routing to new page

I'm banging my head because this should be so simple. I created a new Razor page in my Blazor server-side app that live in ~/pages. Its very simple with a @page "/importhome" declaration at the top. There are two issues which might be related, 1: when I navigate to the page https://localhost:44348/importhome, I get the default page for no route Sorry there is nothing at this address. This is baffling me because with the @page declaration Blazor builds the routes at compile-time, yes?

The second issue is, I added a Syncfusion Blazor Card and its not recognizing the SfCard element. We've used cards all over the app and I verified the dependencies are installed. I have my using statements for Syncfusion in the page. I can't help but think these two things are related somehow? I've tried changing the page name in the directive and I've tried removing all the code except the header and still doesn't work. I've been sifting through google searches but 99% of the results are issues with parameters or conditional routing. Here is the page.

@page "/importhome"

@inherits BasePage

@using Infinity.Pages
@using Infinity.Model
@using Syncfusion.Blazor
@using Syncfusion.Blazor.Cards

<h3>Import Your Data</h3>

<div class="col-xs-6 col-sm-6 col-lg-6 col-md-6">
    <SfCard>
        <CardHeader>
            Import All Your data
        </CardHeader>
        <CardContent>
            From here, you can import your entire database.
        </CardContent>
    </SfCard>
</div>
<div class="col-xs-6 col-sm-6 col-lg-6 col-md-6">
    <SfCard>
        <CardHeader>
            Just Update Your Assets
        </CardHeader>
        <CardContent>
            Click here to update your assets only.
        </CardContent>
    </SfCard>
</div>

@code {

}

Update 1 ************** MrC requested the base page. As you can see its mostly just injecting services. We use this on every page in the app.

using Infinity.Data;
using Infinity.Model;
using Infinity.Services;
using Infinity.Shared;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.JSInterop;
using System;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Infinity.Areas.Identity.Pages.Account;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.WebUtilities;
using SendGrid;

namespace Infinity.Pages
{
    public partial class BasePage : ComponentBase, IDisposable
    {
        [Inject] public IJSRuntime jSRuntime { get; set; }
        [Inject] public DataStoreService _dataStore { get; set; }
        [Inject] public IDbContextFactory<InvictusDbContext> DbFactory { get; set; }
        [Inject] private AuthenticationStateProvider AuthenticationStateProvider { get; set; }
        [Inject] public IHttpContextAccessor httpContextAccessor { get; set; }
        [Inject] public UserManager<ApplicationUser> UserManager { get; set; }
        [Inject] public IEmailSender IEmailSender { get; set; }
        [Inject] public BoxService BoxService { get; set; }
        public ApplicationUser _currentUser { get=>IDS.User; }
        [Inject] public UserService UserService { get; set; }
        [Inject] public NavigationManager _navigationManager { get; set; }
        [Inject] public InvictusDataService IDS { get; set; }
        [Inject] public ValueAddService VAS { get; set; }
        [Inject] public UINotifications UINotifications { get; set; }
        public bool IsClient => IDS.User.UserRoles.Any(x => x.Role.UserRoles.Any(x => x.Role.Name == "Clients"));
        public bool IsAdvisor => IDS.User.UserRoles.Any(x => x.Role.UserRoles.Any(x => x.Role.Name == "Advisor"));
        public bool IsLeadAdvisor => IDS.User.UserRoles.Any(x => x.Role.UserRoles.Any(x => x.Role.Name == "Lead Advisor"));
        public bool IsAdministrator => IDS.User.UserRoles.Any(x => x.Role.UserRoles.Any(x => x.Role.Name == "Administrator"));
        public bool IsRTSAdmin => IDS.User.UserRoles.Any(x => x.Role.UserRoles.Any(x => x.Role.Name == "RTSAdmin"));


        //Needed to call Developer Exceptions  
        [CascadingParameter] public Error Error { get; set; }

        public BasePage()
        {
            UserService = new UserService();

        }

        public async Task CloseMyWindow()
        {
            await jSRuntime.InvokeAsync<object>("close");
        }
        protected override async Task OnInitializedAsync()
        {
        
            var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
            if (!authState.User.Identity.IsAuthenticated)
                _navigationManager.NavigateTo("/");

            //var user = authState.User;

             //_currentUser = await UserManager.FindByNameAsync(httpContextAccessor.HttpContext.User.Identity.Name);
             //UserService.User = _currentUser;
            
            await base.OnInitializedAsync();
        }


        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            await base.OnAfterRenderAsync(firstRender);
        }


        public void Dispose()
        {
            //Todo: ReSharper Suggested this. 
            //UserManager?.Dispose();
        }
    }
}

Upvotes: 2

Views: 2176

Answers (2)

Tony
Tony

Reputation: 17657

This may happen if, for some reason, the Build Action is not set as expected by the compiler.
On the File Properties, check if the Build Action is set to Content

Build Action Content

Upvotes: 5

USMC6072
USMC6072

Reputation: 668

After fighting with this off and on all weekend, I deleted the page and created it new and now it works. It seems like this is a Visual Studio 2022 mystery that won't get solved. Thanks for everyone's input.

Upvotes: 2

Related Questions