How can i make the upload file action automatically once the files selected. means that the action will go to index action without pressing any button? Thanks in advance..
View
<form action="@Url.Action("Index", "Home")" method="post" enctype="multipart/form-data">
@Html.AntiForgeryToken()
<table >
<tr>
<td>
<label>Name:</label>
<input type="text" name="faxnumber" />
</td>
</tr>
<tr>
<td>
<label>Select File:</label>
<input type="file" name="files" id="file" multiple="multiple" />
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Send" id="btnSubmit" />
</td>
</tr>
@ViewBag.Message
</table>
</form>
javascript
<script>
document.getElementById("file").onchange = function () {
document.getElementById("form").submit();
}
</script>
Controller
public ActionResult Index(IEnumerable<HttpPostedFileBase> files)
{
//some code here
}
UPDATE
After selected files, the files will auto uploaded and the details will be stored in object name Document
then back to the view with fail or success message. Then when I hit Send button all details will pass to the Send action in controller. How can I manage this process? The upload part is done already..but now I'm stuck in how can I send all the details to the next action in controller.
public class Document
{
public string Name { get; set; }
public byte[] Binary { get; set; }
public string Path { get; set; }
}
SendController
public ActionResult Send(Document doc)
{
//some code here
}