Show "word" in Shared/_ProductBox.cshtml

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Hace 7 años
Hi,

1. I added to the table  "Product_Category_Mapping" (database site) field "Number" (type - nvarchar(400))
2. Added code and on the page /Admin/Category/Edit/1  - bookmark "Products": field "Number" - It works correctly: add, edit, delete.

How to get field "Number" in Shared/_ProductBox.cshtml ?

Thanks :0)
Hace 7 años
vladundhanna wrote:
Hi,

1. I added to the table  "Product_Category_Mapping" (database site) field "Number" (type - nvarchar(400))
2. Added code and on the page /Admin/Category/Edit/1  - bookmark "Products": field "Number" - It works correctly: add, edit, delete.

How to get field "Number" in Shared/_ProductBox.cshtml ?

Thanks :0)


As of your post , I guess you are changing the core.You can just add your new field in ProductOverviewModel and when  it going to prepare you can assign value and use it in view.
Hace 7 años
vladundhanna wrote:
Hi,

1. I added to the table  "Product_Category_Mapping" (database site) field "Number" (type - nvarchar(400))
2. Added code and on the page /Admin/Category/Edit/1  - bookmark "Products": field "Number" - It works correctly: add, edit, delete.

How to get field "Number" in Shared/_ProductBox.cshtml ?

Thanks :0)


Try with like bellow ==>


@{
    var product = Nop.Core.Infrastructure.EngineContext.Current.Resolve<Nop.Services.Catalog.IProductService>().GetProductById(Model.Id);
    var productCategory = product.ProductCategories.FirstOrDefault();
    var number = productCategory != null ?productCategory.Number  : 0;
}
<span>@number.ToString()</span>
Hace 7 años
Krunalramani wrote:
Hi,

1. I added to the table  "Product_Category_Mapping" (database site) field "Number" (type - nvarchar(400))
2. Added code and on the page /Admin/Category/Edit/1  - bookmark "Products": field "Number" - It works correctly: add, edit, delete.

How to get field "Number" in Shared/_ProductBox.cshtml ?

Thanks :0)

As of your post , I guess you are changing the core.You can just add your new field in ProductOverviewModel and when  it going to prepare you can assign value and use it in view.


The product is assigned to the category. To this regard, the administrator specifies a "word".

"Word" is not taken from the table "Product" and "Category". The word is taken from the table "Product_Category_Mapping"

Added field "Number" in ProductOverviewModel - "word" not reflected in _ProductBox.cshtml
Hace 7 años
sohel wrote:
Hi,

1. I added to the table  "Product_Category_Mapping" (database site) field "Number" (type - nvarchar(400))
2. Added code and on the page /Admin/Category/Edit/1  - bookmark "Products": field "Number" - It works correctly: add, edit, delete.

How to get field "Number" in Shared/_ProductBox.cshtml ?

Thanks :0)

Try with like bellow ==>


@{
    var product = Nop.Core.Infrastructure.EngineContext.Current.Resolve<Nop.Services.Catalog.IProductService>().GetProductById(Model.Id);
    var productCategory = product.ProductCategories.FirstOrDefault();
    var number = productCategory != null ?productCategory.Number  : 0;
}
<span>@number.ToString()</span>


Thanks!

So works

@{
  var product = EngineContext.Current.Resolve<Nop.Services.Catalog.IProductService>().GetProductById(Model.Id);
        var productCategory = product.ProductCategories.FirstOrDefault();
        var number = productCategory != null ? productCategory.Number.ToString() : "";
}

<span>@number.ToString()</span>



But if the field "Number" - is empty, an error page:
Object reference does not point to an object instance.
var number = productCategory != null ? productCategory.Number.ToString() : "";
Hace 7 años
Your Number type already string, So just try with bellow


@{
  var product = EngineContext.Current.Resolve<Nop.Services.Catalog.IProductService>().GetProductById(Model.Id);
        var productCategory = product.ProductCategories.FirstOrDefault();
        var number = productCategory != null ? productCategory.Number : "";
}

<span>@number</span>
Hace 7 años
sohel wrote:
Your Number type already string, So just try with bellow


@{
  var product = EngineContext.Current.Resolve<Nop.Services.Catalog.IProductService>().GetProductById(Model.Id);
        var productCategory = product.ProductCategories.FirstOrDefault();
        var number = productCategory != null ? productCategory.Number : "";
}

<span>@number</span>


Thanks!
Working!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.