I am trying to grab files from a directory and I am trying to let the user select a file from a list to be later processed.
This is the code that gets the files.
[HttpGet]
public ActionResult GetFiles()
{
DirectoryInfo dinfo = new DirectoryInfo(@"C:\TestDirectory");
List<FileInfo> Files = dinfo.GetFiles("*.txt").ToList();
return PartialView("_File", Files);
}
And this is the partial view that that is going to be in the modal for now.
@model List<FileInfo>
@Html.ListBoxFor(model => model, new SelectList(Model).AsEnumerable())
How I am calling the partial view from main view:
<div class="row">
<div class="modal fade" id="bootstrapDialog" tabindex="-1" role="dialog" aria-labelledby="myModal-label" aria-hidden="true"></div>
</div>
<div class="btn btn-default browseButton">
<span class="glyphicon glyphicon-folder-open browseDialog" data-url="@Url.Action("GetFiles","Home", null)"></span>
<span class="browseDialog" data-url="@Url.Action("GetFiles","Home", null)">Browse...</span>
</div>
@section scripts {
<script>
$(document).ready(function () {
$('.browseDialog').click(function () {
var url = $(this).data('url');
$.get(url, function (data) {
$('#bootstrapDialog').html(data);
$('#bootstrapDialog').modal('show');
});
});
});
</script>
}
The file information is being retreived but the listbox is not created. The listbox gives an except that the value cannot be null or empty. Do I have to create something else that has to be passed into this listbox?
And how would I allow the user to select an item to pass back to the screen behind to modal to populate a textbox?