Insert multiple rows into a table in asp.net MVC

Hi, I have the following script

Table - Items id int (PK), name varchar(100) Table - Category id int (PK), name varchar(100) Table - Category_item category_id int (FK), item_id int (FK) 

I am using Asp.Net MVC and Entitydatamodel . In the view, I have a drop-down list to show categories and check boxes for displaying the item.

I want to insert into the table - Category_item when I select the category and elements that take into account the current situation. How can I do it? How to transfer values ​​from a view to a controller?

+4
source share
1 answer

Andersor: it depends. But the general case (RAZOR)

@ Html.DropDownList (category, db.Categories.Select (cat => new SelectListItem () {Text = cat.Name, Value = cat.Id, Selected = (false / true)}) ToList ()) ;.

You can use Html.DropDownListFor , and then the Save action will already be limited to the correct value. 'db' is the context of the model.

+1
source

Source: https://habr.com/ru/post/1343176/


All Articles