c# - Handling multiple Multi-File Inputs in MVC -
i new mvc, , have issue can't seem resolve. have seen several articles on similar issues, nothing can make fit bill need achieve.
i have mvc4 project, , need have multiple multi-file inputs on page, , need able distinguish between files submitted via input.
i have seen this article suggested having multiple post action args, code seems handle them single list.
here controller code :
public actionresult projectdocuments(c4tbl_uploadedfiles c4tbl_uploadedfiles, ienumerable<httppostedfilebase> file1, ienumerable<httppostedfilebase> file2) { try { foreach (var file in file1) { if (file.contentlength > 0) { //handle first file list } } foreach (var file in file2) { if (file.contentlength > 0) { //handle second file list } }
here view code :
<table border="0" id="csstable" class="nobg"> <tr> <th style="width: 100px; min-width: 100px; max-width: 100px"> <b>type</b> </th> <th style="width: 400px; min-width: 400px; max-width: 400px"> <b>file upload</b> </th> <th style="width: 500px; min-width: 500px; max-width: 500px"> <b>status</b> </th> </tr> <tr> <td style="width: 100px; min-width: 100px; max-width: 100px"> <b>blueprint(s)</b> </td> <td style="width: 400px; min-width: 400px; max-width: 400px"> <input type="file" name="file1" id="bp" multiple style="width: 380px"/> </td> <td style="width: 500px; min-width: 500px; max-width: 500px; text-align: left"> @html.radiobutton("submitted", "yes", false, new { @style = "width: 25px;", groupname="group1" }) uploaded @html.radiobutton("submitted", "no", false, new { @style = "width: 25px;", groupname="group1" }) not uploaded @html.radiobutton("submitted", "n/a", false, new { @style = "width: 25px;", groupname="group1" }) not applicable </td> </tr> <tr> <td style="width: 100px; min-width: 100px; max-width: 100px"> <b>recovery guide(s)</b> </td> <td style="width: 400px; min-width: 400px; max-width: 400px"> <input type="file" name="file2" id="rg" multiple style="width: 380px"/> </td> <td style="width: 500px; min-width: 500px; max-width: 500px; text-align: left"> @html.radiobutton("submitted", "yes", false, new { @style = "width: 25px;", groupname="group2" }) uploaded @html.radiobutton("submitted", "no", false, new { @style = "width: 25px;", groupname="group2" }) not uploaded @html.radiobutton("submitted", "n/a", false, new { @style = "width: 25px;", groupname="group2" }) not applicable </td> <td> <input type="submit" value="submit" name="submit" /> </td> </tr> </table>
i need able accept or of inputs having files provided, , need know of inputs files submitted via, know type of file can create relevant db entries in tables.
can see simple solution , point me in right direction?
thanks answers. have marked answered current edit post works although sure there more efficient ways this.
this working controller code :
public actionresult projectdocuments(c4tbl_uploadedfiles c4tbl_uploadedfiles, ienumerable<httppostedfilebase> file1, ienumerable<httppostedfilebase> file2) { try { foreach (var file in file1) { if (file.contentlength > 0) { //handle first file list } } foreach (var file in file2) { if (file.contentlength > 0) { //handle second file list } }
this working view code :
<table border="0" id="csstable" class="nobg"> <tr> <th style="width: 100px; min-width: 100px; max-width: 100px"> <b>type</b> </th> <th style="width: 400px; min-width: 400px; max-width: 400px"> <b>file upload</b> </th> <th style="width: 500px; min-width: 500px; max-width: 500px"> <b>status</b> </th> </tr> <tr> <td style="width: 100px; min-width: 100px; max-width: 100px"> <b>blueprint(s)</b> </td> <td style="width: 400px; min-width: 400px; max-width: 400px"> <input type="file" name="file1" id="bp" multiple style="width: 380px"/> </td> <td style="width: 500px; min-width: 500px; max-width: 500px; text-align: left"> @html.radiobutton("submitted", "yes", false, new { @style = "width: 25px;", groupname="group1" }) uploaded @html.radiobutton("submitted", "no", false, new { @style = "width: 25px;", groupname="group1" }) not uploaded @html.radiobutton("submitted", "n/a", false, new { @style = "width: 25px;", groupname="group1" }) not applicable </td> </tr> <tr> <td style="width: 100px; min-width: 100px; max-width: 100px"> <b>recovery guide(s)</b> </td> <td style="width: 400px; min-width: 400px; max-width: 400px"> <input type="file" name="file2" id="rg" multiple style="width: 380px"/> </td> <td style="width: 500px; min-width: 500px; max-width: 500px; text-align: left"> @html.radiobutton("submitted", "yes", false, new { @style = "width: 25px;", groupname="group2" }) uploaded @html.radiobutton("submitted", "no", false, new { @style = "width: 25px;", groupname="group2" }) not uploaded @html.radiobutton("submitted", "n/a", false, new { @style = "width: 25px;", groupname="group2" }) not applicable </td> <td> <input type="submit" value="submit" name="submit" /> </td> </tr>
thanks , suggestions
Comments
Post a Comment