how to I start?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 anos atrás
Hi,

I need to be pointed in the right direction - I am pretty new to MVC and browsing through NopCommerce can be a bit overwhelming at first.

I have a table with additional information about products. I want to present this info in non standard way on the product page. I figured that the best way will be to insert the additional functionliaty via Html.Action. I imagine it would look like this:

@Html.Action("AdditionalProductInfo", "Catalog", new {productId = Model.Id})

All right next step I need to add appropriate view and ChildAction to the CatalogController.cs


[ChildActionOnly]
public ActionResult AdditionalProductInfo (int productId)
{
   //what goes here?
}

I have created a new class in Nop.Core.Domain and even a mapping in Nop.Data.Mapping. Bang! (more or less) and I have a class in my DB :-).

This is what I know. Now comes the question :-)

How do I access the data from my table?

Do I need to obtain a reference to existing (already initialized) DbContext class to run some LINQ queries? Or do I need to create one from scratch? Or maybe I need to do something totally different?

Any help or suggestions appreciated!

Filip
12 anos atrás
You've almost done it. You forgot only about services (Nop.Services.dll assembly). Don't use DbContext in your controller. Use services. To get an idea have a look at the following two classes: Nop.Services.Affiliates.AffiliateService and Nop.Services.Affiliates.IAffiliateService. AffiliateService has CRUD operations for appropriate entities. Then inject this service into your controller and use it there. That's all

P.S. Don't forget to register interface in Nop.Web.Framework.DependencyRegistrar class
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.