1

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

4
  • Can you please post your code? Commented Sep 24, 2019 at 5:42
  • @ZachPedigo Sir, i have updated my code please find. Commented Sep 24, 2019 at 11:24
  • Honestly, I would suggest creating the dropdown list in vanilla JS rather than in the HTML. Have you considered giving this approach a shot? Or is there a specific reason you need to use html? Commented Sep 24, 2019 at 19:39
  • @ZachPedigo, I am not that much familiar with JavaScript / Jquery or Vanilla JS, so I am using HTML and facing the issue. Commented Sep 26, 2019 at 9:51

1 Answer 1

0

Thanks to all those people who have shown their interest in my question. while searching more about it, i got another stack overflow question, where i got answer as per my requirement.

Click here to visit the similar question.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.