The name 'OfficialSite' does not exist in the current context, when adding Footer component to a theme

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
2 年 前
I'm upgrading from 4.20 to 4.40.3 and working my way through the process (normal theme pains and such). The final piece is that the copyright banner doesn't resolve when I put it in a theme, which worked without issue in 4.20. From the error log:

...\www\Themes\MyThemeA\Views\Shared\Components\Footer\Default.cshtml(132,31): error CS0103: The name 'OfficialSite' does not exist in the current context

The code is (when placed in a theme):
Powered by <a href="@(OfficialSite.Main)">nopCommerce</a>


I haven't made any major changes to that file, only some minimal html/styling changes. Am I missing a using statement? Maybe hard code the url? I can live without it in the meantime, but does anyone know the trick to getting that to work? Thanks.
2 年 前
Do you have this at the top of your view?


@model FooterModel

@using Nop.Core
@using Nop.Core.Domain.Tax

@inject IWorkContext workContext
2 年 前
Yes, exactly like that.

I even removed all my code, with exception to the minor modifications you have to make to the widget zone line. Therefore, it's basically the default file that exists at: www/Views/Shared/Components/Footer/Default.cshtml path

With exception to this line (which shows up a couple lines after the copyright banner):
@await Component.InvokeAsync("Widget", new { widgetZone = "footer" })
2 年 前
Does it work fine if you're just using the default footer, rather than the one in your theme?
2 年 前
Also, what does your _viewimports.cshtml in your theme look like - like this?

@inherits Nop.Web.Framework.Mvc.Razor.NopRazorPage<TModel>
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@*we remove the default InputTagHelper to prevent the checkbox duplicating: https://stackoverflow.com/questions/42544961/asp-net-core-custom-input-tag-helper-rendering-duplicate-checkboxes*@
@removeTagHelper Microsoft.AspNetCore.Mvc.TagHelpers.InputTagHelper, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Nop.Web.Framework
@addTagHelper *, MiniProfiler.AspNetCore.Mvc

@using Microsoft.AspNetCore.Mvc.ViewFeatures
@using Microsoft.Extensions.Primitives
@using Nop.Web.Extensions
@using Nop.Web.Framework
@using Nop.Web.Framework.Extensions
@using Nop.Web.Framework.Infrastructure
@using Nop.Web.Framework.Models
@using Nop.Web.Framework.Security.Captcha
@using Nop.Web.Framework.Security.Honeypot
@using Nop.Web.Framework.Themes
@using Nop.Web.Framework.UI
@using Nop.Web.Models.Blogs
@using Nop.Web.Models.Boards
@using Nop.Web.Models.Catalog
@using Nop.Web.Models.Checkout
@using Nop.Web.Models.Cms
@using Nop.Web.Models.Common
@using Nop.Web.Models.Customer
@using Nop.Web.Models.Media
@using Nop.Web.Models.News
@using Nop.Web.Models.Newsletter
@using Nop.Web.Models.Order
@using Nop.Web.Models.Polls
@using Nop.Web.Models.PrivateMessages
@using Nop.Web.Models.Profile
@using Nop.Web.Models.ShoppingCart
@using Nop.Web.Models.Topics
@using Nop.Web.Models.Vendors
2 年 前
I thought you were onto something with the _ViewImports.cshtml file as I can't remember ever even giving that a look. Mine was last modified on 2017, definitely not recent.

I just swapped that file out for the one in the DefaultClean theme (which matches the one you posted) and still the same error (I also restarted/recycled the site after swapping the file).

To answer your first question, it works fine when it's in the regular Views structure. It's only when I add it to my theme that it starts giving that 'OfficialSite' context error.

Many thanks for your help!
2 年 前
Rather than faffing on, just change @(OfficialSite.Main) to https://www.nopcommerce.com/
2 年 前
This also works.

href="@(Nop.Services.Common.NopLinksDefaults.OfficialSite.Main)"


And, adding this to your viewimports works too:


@using Nop.Services.Common
@using static Nop.Services.Common.NopLinksDefaults


This means you can just use: @(OfficialSite.Main) in your view
2 年 前
Excellent, I was leaning towards your first solution, but more prefer your second. Anyway, both simple, compact fixes for when I'm trying to remember again a year or more from now on the next upgrade. Thanks again for your speedy help!
2 年 前
No problem :)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.