Это открывает эту форму в модальном режиме:

Здесь вы можете редактировать существующие значения, удалять их или добавлять новые:

Таким образом, оно может иметь любое количество значений!
CSHTML для это:
Код: Выделить всё
@using (Html.BeginForm("EditDropDown", "Incidents", FormMethod.Post, new { onsubmit = "validateCustomTolerances()", id = "modal-form" }))
{
@foreach (var opt in Model.IncRptOptions)
{
@if (opt.Type == "Action")
{
[/i]
}
}
Add Option
@*------ Hidden form content (required by controller action) ------*@
[i]
@*------ Form buttons ------*@
Save
Cancel
}
Код: Выделить всё
// Deletes the existing option next to the 'bin' button user clicks it.
document.querySelectorAll('.delete-existing').forEach(item => {
item.addEventListener('click', event => {
let existingParent = item.parentElement;
existingParent.remove();
});
});
// Event listeners for the 'add option' button
let addOption = document.querySelector('#add-option');
// Creates the form input element for an additional option when button clicked
addOption.addEventListener('click', function () {
let parent = document.querySelector('#additional-options-here');
let html = `
[/i]
`;
let template = document.createElement('div');
template.setAttribute('class', 'IncRpt-opt-modalDisp')
template.innerHTML = html;
let finalHTML = template;
finalHTML.querySelector('.delete-added').addEventListener('click', deleteAddedElement);
parent.appendChild(finalHTML);
});
// Deletes the added option elements when user clicks on the 'bin' icons
function deleteAddedElement() {
let parent = this.parentElement;
parent.remove();
}
Используя Flask, я использовал request.form.getList("Input-name-value"). Как это можно сделать в ASP.NET?
Подробнее здесь: https://stackoverflow.com/questions/764 ... ield-count
Мобильная версия