Show "word" in Shared/_ProductBox.cshtml

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 лет назад
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)
7 лет назад
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.
7 лет назад
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>
7 лет назад
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
7 лет назад
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() : "";
7 лет назад
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>
7 лет назад
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.