var drives = Directory.GetLogicalDrives().ToList(); ViewBag.Drives = new SelectList(drives);
public JsonResult GetDirectories(string drive) { var d = new List<string>(); foreach (var directories in new DirectoryInfo(drive).GetDirectories()) { d.Add(directories.Name); } var dr = new SelectList(d.ToList()); return Json(dr, JsonRequestBehavior.AllowGet); }
<script type="text/javascript"> $(document).ready(function(){ $("#Drives").change(function () { var d = $("#Drives").val(); $.ajax({ type: "post", url: "/Explorer/GetDirectories?drive=" + d, data: { drives: $("#Drives").val() }, data: "json", traditional: true, success: function (data) { var folders = ''; for (var i = 0; i < data.length; i++) { folders = folders + '<li class="list-group-item"> <a href="" class = "fa fa-folder">'+data[i].Text+'</a> </li>'; } $('#folders').html(folders); } }); }); }); </script>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)