syntaxe block test with "contains"

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Hi All,

I want to do a test like this in the page ProductTemplate.Simple.cshtml:

if (attribute.Name) contains ("rmell")

I don't know how to write this in nopCommerce 3.9, could you help me please

Thank you!
6 years ago
This should do it:

if(Model.ProductAttributes.Any(attr => attr.Name == "YourAttributeName"))
6 years ago
Hi Pete,

I get this error:

'System.Collections.Generic.IList<Nop.Web.Models.Catalog.ProductDetailsModel.ProductAttributeModel>' does not contain a definition for 'ProductAttributes' and no extension method 'ProductAttributes' accepting a first argument of type 'System.Collections.Generic.IList<Nop.Web.Models.Catalog.ProductDetailsModel.ProductAttributeModel>' could be found (are you missing a using directive or an assembly reference?)

I want to more explain my problem; now i use a test on language + name attribute and all my test give me a result, but i found a problem with one attribute because it contains a special characters, so I thought to use contains to eliminate the special caracters.

please see my test:

if ((workContext.WorkingLanguage.Id == 11) && (attribute.Name == "Ärmellänge"))
    { ............. }


I think this test did not give me a result because the 2 special caracters Ä and ä , so i think to change the test like this, but i don't know how to use contains here:

if ((workContext.WorkingLanguage.Id == 11) && (attribute.Name contains "rmell"))
    { ............... }


kind regards!
6 years ago
Bivolini wrote:
I get this error:

'System.Collections.Generic.IList<Nop.Web.Models.Catalog.ProductDetailsModel.ProductAttributeModel>' does not contain a definition for 'ProductAttributes' and no extension method 'ProductAttributes' accepting a first argument of type 'System.Collections.Generic.IList<Nop.Web.Models.Catalog.ProductDetailsModel.ProductAttributeModel>' could be found (are you missing a using directive or an assembly reference?)

You said you wanted to put the code in the ProductTemplate.Simple.cshtml view, the error would suggest you're actually working on the _ProductAttributes.cshtml partial view.

Bivolini wrote:
I think this test did not give me a result because the 2 special caracters Ä and ä , so i think to change the test like this, but i don't know how to use contains here:

if ((workContext.WorkingLanguage.Id == 11) && (attribute.Name contains "rmell"))
    { ............... }

You can just use String.contains like:

attribute.Name.contains("rmell")

or possibly String.compare if you wanted accent insensitive string comparison (not tested):

String.Compare(attribute.Name, "Ärmellänge", CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace) == 0
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.