I have the following code. The model is an Asset. However, what I want is to assign a user for each Asset in View Model through @Html.DropDownListFor(model => model.UserFromTable, new SelectList(Model.UsersFromTable, "UserName", "UserName"))
.
The thing is that I tried appropriate SelectList<>
etc., but I don't know how to assign users from the dropdownlist in users column to assets in ViewModel. Another thing is that I don't receive my selection in ViewModel after Post. I can pass there some checkbox values but not the selections from the above dropdownlist.
I read some posts on stackoverflow and found out that some similar tasks require foreach. There is already one foreach loop in the code. I believe I should work on var item in Model.Assets
somehow. I also have a separate CRUD Edit cshtml page for editing one single Asset but I want to save changes in user dropdownlist to all Assets on the current page.
Is it possible and how can I do it?
@Html.Partial("AssetsFiltering", Model.AssetsFilteringVM)
@foreach (var item in Model.Assets)
{
<tr class="data-rows">
<td>@Html.Span(item.Id)</td>
....
<td>
@Html.DropDownListFor(model => model.UserFromTable, new SelectList(Model.UsersFromTable, "UserName", "UserName"))
</td>