You can do something like this
public class EventsDto
{
//other properties
public List<string> ParticipantsIds { get; set; }
}
Then in view so after submit you can get list of ParticipantsIds you can loop on them then initiate new objects of EventsParticipants finally add them to DB
@model EventsDto
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<a onclick="addToList(this)">(click me)User to add into list(click me)</a>
<br/>
<select asp-for="ParticipantsIds" multiple id="participantsList"
style="height: 7em; overflow-y: scroll; width: 10em"></select>
<br/>
<button type="button" onclick="removeFromList()">Remove</button>
<button type="button" onclick="clearList()">Clear list</button>
<script>
function addToList(usuario) {
var lista = document.getElementById("participantsList");
var item = document.createElement("option");
item.text = $(usuario).text()
lista.appendChild(item);
}
function removeFromList() {
$("#participantsList option:selected").remove();
}
function clearList() {
$("#participantsList").empty();
}
</script>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…