How do I use nop-select tag helper in my plugin?

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

I'm using nopCommerce 4.0 with source.

In my plugin Configure.cshtml view, I want to present a dropdown list of Parameters (names of properties in a model class) defined this way:

public class Product
    {
        public int product_id { get; set; }
        public string model_code { get; set; }
        public string full_product_name { get; set; }
            ... more properties ...
        public System.DateTime expire_date { get; set; }
     }


I tried to clone from another nop-select in the Admin project and they all seem to reference an enum in their asp-items tag helper.

This is what my Configuration model looks like:

using Nop.Web.Framework.Mvc.ModelBinding;
using Nop.Web.Framework.Mvc.Models;

namespace Nop.Plugin.Misc.Chinavasion.Models
{
    public class ConfigurationModel : BaseNopModel
    {
        public int ActiveStoreScopeConfiguration { get; set; }

        [NopResourceDisplayName("Plugins.Misc.Chinavasion.ChinavasionUrl")]
        public string ChinavasionUrl { get; set; }
        public bool ChinavasionUrl_OverrideForStore { get; set; }

        [NopResourceDisplayName("Plugins.Misc.Chinavasion.ChinavasionPath")]
        public string ChinavasionPath { get; set; }
        public bool ChinavasionPath_OverrideForStore { get; set; }

        [NopResourceDisplayName("Plugins.Misc.Chinavasion.ChinavasionAPIKey")]
        public string ChinavasionAPIKey { get; set; }
        ublic bool ChinavasionAPIKey_OverrideForStore { get; set; }

        [NopResourceDisplayName("Plugins.Misc.Chinavasion.Parameters")]
        public Product Parameters { get; set; }
        public bool Parameters_OverrideForStore { get; set; }
     }
}


and this is what I have so far for my nop-select:

<div class="col-md-9">
    <nop-select asp-for="Parameters" asp-items="@(((Product)Model.Parameters).ToSelectList())" />
    <span asp-validation-for="Parameters"></span>
</div>


It doesn't like the ToSelectList() saying "Product does not contain a definition for 'ToSelectList' and no extension method 'ToSelectList' accepting a first argument of type 'Product'"

Does anyone know how I should define my Product class to accomplish this?

Thanks,
Tony
5 years ago
@inherits Nop.Web.Framework.Mvc.Razor.NopRazorPage<TModel>
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Nop.Web.Framework

add this to your view
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.