Click here to Skip to main content
15,499,430 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have dynamic inputs. The code works properly, but the input file type passed null.

What I have tried:

the AttachmentsDto:
C#
 public class AttachmentsDto
{
    public string Name { get; set; }
    public int AttachType { get; set; }
    public List<iformfile> Photos { get; set; }
    public string? CreatedBy { get; set; }
    public string? ModifiedBy { get; set; }
    public DateTime CreatedOn { get; set; }
    public DateTime? ModifiedOn { get; set; }
    public bool IsDeleted { get; set; } = false;
}

the photos input #Photos file passed null, Although input #Name pass the value:
JavaScript
$("#addRow").click(function ()
{
    var rowCount = parseInt($("#total").val());
    rowCount++;
    $("#total").val(rowCount);
    console.log(rowCount);
    var html = '';
    html += '<div id="inputRow">';
    html += '<input type="text" name="DynamicNoteList[' + (rowCount - 1) + '].Note"  class="form-control " />';
    html += '</br>';
    html += '<input type="file" id="Photos" name="Attachments[' + (rowCount - 1) + '].Photos" multiple="multiple"  class="form-control custom-file-input"/>';
    html += '<input type="text" name="Attachments[' + (rowCount - 1) + '].Name" id="Name " class="form-control"/>';

    //add more inputs here...
    html += '<button id="removeRow" type="button" class="btn btn-danger">Delete</button>';
    html += '</div>';

    $('#newRow').append(html);
    });
    $(document).on('click', '#removeRow', function ()
    {
    var rowCount = parseInt($("#total").val());
    rowCount--;
    $("#total").val(rowCount);
    $(this).closest('#inputRow').remove();
});
Posted
Updated 24-Apr-22 18:53pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900