NopCommerce 4.0 render Action on view, need to convert to Component but how?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 4 ans
Hello,

I've been at this for 4 hours now and cannot figure out how to convert my code (from NopCommerce 3.6) to the new 4.X of using Components.

I have the following call on my Product Details View:
@Html.Action("HassleFreeProduct", "Product", new { productId = Model.Id })


In my controller I have an Action Method that returns HTML to the view where it's rendered.:

public ActionResult HassleFreeProduct(int productId)
        {
            var model = new model();
            return View(model);
        }


How do I do this on NopCommerce 4.0?

So far I've figured out I have to convert my ActioMethod to a Component but what exactly does that mean?  I cannot find any examples in the code.

Can someone provide an example on how to do this in NopCommerce 4.0 +
Il y a 4 ans
I guess I needed one more hour...

I think I figured it out, at least I got my code to work!

Action Methods in Controllers are now Components, Look at Nop.Web.Components
Create a class for your new component and derive from NopViewComponent
Implement the Invoke Method and put your old Action Method code there

Then add a view in \Theme\Views\Shared\Components or an appropiate location.

Call the Action from your View like this:
@await Component.InvokeAsync("HassleFreeProduct", new { productId = Model.Id })


And see your code come alive!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.