Good day
I really need your help as I am currently stuck, need your opinions on how to solve this problem, please kindly look at my code .
Views:
@using (Html.BeginForm("Test", "Student", FormMethod.Post))
{
for (int i = 0; i < Model.Count(); i++)
{
@Html.TextBoxFor(model => Model[i].Name)
<input class="btn btn-default" type="submit" value="submit all student names"/>
<form action="/Student/Upload/@Model[i].Id" method="post" enctype="multipart/form-data">
<input class="btn btn-default" type="file" name="photofile" value="photofile" style="width: 100%;"/>
<input class="btn btn-default" value="submit files" type="submit"/>
</form>
}
}
Controller:
public async Task<IActionResult> Upload(int id, IFormFile photofile)
[HttpPost, Route("Student/Upload/{id:int=0}")]
public IActionResult Test(List<Student> students)
So basically what I am trying to do is that when the form is being loaded, there will be student names and a button to submit all names, so when the user modify any changes in the textbox and click submit, the entire collections will be passed into the Test as List students and modified accordingly, it works perfectly fine until I have to introduce the Upload into it as well.
So now I have upload and once the form is loaded, names of student textbox and an submit buttons and also numbers of input based on the number of students as well as input button to submit the file, I need to submit one file at a time only and only one is affected, the upload is working successfully too EXCEPT now when I modify the student names and submit, only the first Index is working, the rest the List students only accept first index modification, the rest it will always show List = 0, I believe it is due to the problem of form being replicated, invalid html, but is there any way to override this to make it works?
I need the upload form to be inside because I need the method"post" enctype="" and also I need the input to be aside/above the student name textbox.
Thanks a lot