[ViewComponent(Name = "PayTabsViewComponent")]

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 year ago
dears,
i need  some help.
as i am upgrading custom plugin from 4 to 4.6
i did some search and updated the plugin buisness and it compile fine now
i need to call the viewcompnent of this plugin inside custom view not core view
so i used
@await Component.InvokeAsync("PayTabsViewComponent")

inside the custom view which i am routing to it by the rout of checkout controller
routeBuilder.MapLocalizedRoute("Check-out", "checkout/",
         new { controller = "Checkout", action = "PaymentCheckOut" });

and to display the component i am using
@model Nop.Plugin.Payments.PayTabs.Models.PayTabsModel
@using Nop.Core
@inject IWebHelper webHelper
@{
    Layout = "_ColumnsOne";

    //scripts
    //Html.AddScriptParts(ResourceLocation.Footer, "~/js/public.accordion.js");
    //Html.AddScriptParts(ResourceLocation.Footer, "~/js/public.onepagecheckout.js");

    var storeLocation = webHelper.GetStoreLocation();

    //title
    Html.AddTitleParts(T("PageTitle.Checkout").Text);
    //page class
    Html.AppendPageCssClassParts("html-checkout-page");
}
<div class="page checkout-page">
    <div class="page-title">
        <h1>@T("Checkout")</h1>
    </div>
    <div class="page-body checkout-data">
        @if (TempData["CartIsEmpty"] == null)
        {
            @await Component.InvokeAsync("PayTabsViewComponent")
        }
        else
        {
        <div class="alert alert-danger alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">×</span>
            </button>
            <h4><span class="glyphicon glyphicon-warning-sign"></span> @T("Common.Warning")</h4>
            @TempData["ErrorMessage"]
        </div>
        }
    </div>
    <script type="text/javascript" asp-location="Footer">

    </script>
</div>

and i am getting this error
InvalidOperationException: A view component named 'PayTabsViewComponent' could not be found. A view component must be a public non-abstract class, not contain any generic parameters, and either be decorated with 'ViewComponentAttribute' or have a class name ending with the 'ViewComponent' suffix. A view component must not be decorated with 'NonViewComponentAttribute'.

can you help me?
1 year ago
Hello,

You need to add like this:
@await Component.InvokeAsync(typeof(PayTabsViewComponent))


#6081 Used ViewComponent's type instead of name for strong typing
1 year ago
dear Sagar
viewcomponent is in the plugin so i need to add refrence of it to Nop.Web
and this will cauze cycle error as plugin already have refernce for Nop.Web
so please help.
1 year ago
If you added plugin reference in Nop.Web project then please remove it.
Please let me know what is your purpose to add your view component in nop.web project view file.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.