Extending Models in NC2.2

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 12 ans
Hi,I 'm developing my oun Plugin,I need to extend the ProductModel,
I tried partial class style but I get an error indecating that ProductModel is placed in two diffrent DLLs !

So,I inhert ProductModel to use the new class in
my view instead of ProductModel,because I mainly need to nest the CheckModel class under ProductModel.

my Model code:

namespace Nop.Web.Models.Catalog
{
    public class Keem_ProductModel : ProductModel
    {
        public Keem_ProductModel()
            : base()
        {
           CheckModels = new List<CheckModel>();
        }

        public IList<CheckModel> CheckModels { get; set; }

        public class CheckModel : BaseNopModel
        {
            public CheckAvailabilityModel()
            {
                //some code

            }
       }

          
        

in the view:
@model Nop.Web.Models.Catalog.Keem_ProductModel

I get this error:

The model item passed into the dictionary is of type 'Nop.Web.Models.Catalog.ProductModel', but this dictionary requires a model item of type 'Nop.Web.Models.Catalog.Keem_ProductModel'.

Any idea ho to extend the Model ,I only need to pass my newly created CkeckModel to a partialview that is in a view
that use the ProductModel.

     Thanks
Il y a 12 ans
Keem wrote:
Hi,I 'm developing my oun Plugin,I need to extend the ProductModel,
I tried partial class style but I get an error indecating that ProductModel is placed in two diffrent DLLs !

So,I inhert ProductModel to use the new class in
my view instead of ProductModel,because I mainly need to nest the CheckModel class under ProductModel.

my Model code:

namespace Nop.Web.Models.Catalog
{
    public class Keem_ProductModel : ProductModel
    {
        public Keem_ProductModel()
            : base()
        {
           CheckModels = new List<CheckModel>();
        }

        public IList<CheckModel> CheckModels { get; set; }

        public class CheckModel : BaseNopModel
        {
            public CheckAvailabilityModel()
            {
                //some code

            }
       }

          
        

in the view:
@model Nop.Web.Models.Catalog.Keem_ProductModel

I get this error:

The model item passed into the dictionary is of type 'Nop.Web.Models.Catalog.ProductModel', but this dictionary requires a model item of type 'Nop.Web.Models.Catalog.Keem_ProductModel'.

Any idea ho to extend the Model ,I only need to pass my newly created CkeckModel to a partialview that is in a view
that use the ProductModel.

     Thanks


Hi Keem,

I'm having a hard time following the problem you present. If I were trying to "extend" the ProductModel in a plugin I would do something like the following:


//Contrller
public class PluginController {
   public ActionResult View(int productId){
        return View(new PluginProductModel());
   }

}


//model
public class PluginProductModel {
    public bool IsAvailable { get; set; }
    public ProductModel Product {get;set; }
}


If you're trying to change how previously existing views work, then a plugin by itself is not the answer.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.