I am creating a product, where i will select multiple categories from multiple select dropdown list. product information will be saved in product table
Product_Id Name Description
1001 Abc Abcdescription
1002 Xyz Xyzdescription
and selected categories will be saved in another table product_cat_type by product_Id
Type_Id Product_Id Category
1 1001 Electronics
2 1001 Devices
3 1001 Gadgets
now i want to update product 1001, all data showing in their respective boxes but multiple select drop down not populating with their previously select categories.
Controller
model.prodcategory= new SelectList(db.Product_category.ToList(), "Category_id", "Category_name");
Viewmodel
[NotMapped]
public int[] Category_iid { get; set; }
public IEnumerable<SelectListItem> prodcategory{ get; set; }
View Page
@Html.DropDownListFor(model => model.Category_iid, Model.prodcategory, "Select Category", new { @class = "form-control m-select2", multiple = "multiple", id = "kt_select2_3" })
now i am trying to append from product_cat_type Product_Id column values to Category_iid
present output click here
expected output click here
Note: I am doing this by using linq code without using any ajax, jquery or json