1
In Asp.net core Razor pages to pass data from a form declared as follows:
[BindProperty]
public int NMembro1 { get; set; }
Where on the form side the tag input
is stated as follows:
<input style="max-width:5.75rem; border: 1px solid #ccc; border-radius: 3px;" name="NMembro1' type="number" min="1">
Then I realize the attribute name
tag input
has the same name as the variable in backend. name="NMembro1'
[BindProperty]
public int NMembro1 { get; set; }
After the framing step explain the problem:
This input tag is created dynamically injavascript, then to get the data from view
I need to dynamically declare these variables.
Follow the code below javascript
let html = "";
for (var i = 0; i < arr.length; i++)
{
html += '<input style="max-width:5.75rem; border: 1px solid #ccc; border-radius: 3px;" name="NMembro' + i +'" type="number" min="1">';
}
Something that worked was to declare the variables in the following form:
[BindProperty]
public int NMembro1 { get; set; }
[BindProperty]
public int NMembro2 { get; set; }
...
But the problem remains: If I don’t know how many variables are generated in javascript as I can state them this way on the side of c#?
After reading some documentation I tried something of this kind
[BindProperty]
public Dictionary<string, object> NMembro { get; set; }
But it didn’t help because I still couldn’t bid