protected async override Task <IEnumerable <SelectListItem> > GetSelectListItemsAsync(SelectListContext context) { var dataValueField = nameof(FileInfo.FullName); if (!Path.EndsWith(@"\")) { Path = Path + @"\"; } var hostingEnvironment = context.HttpContext.RequestServices.GetRequiredService <IHostingEnvironment>(); var mappedWwwPath = hostingEnvironment.MapWwwPath(Path); var mappedContentPath = hostingEnvironment.MapContentPath(Path); var searchPath = Path; var root = ""; var webFolder = false; if (mappedWwwPath != mappedContentPath) { searchPath = mappedContentPath; root = hostingEnvironment.ContentRootPath + @"\"; if (Directory.Exists(mappedWwwPath)) { webFolder = true; searchPath = mappedWwwPath; root = hostingEnvironment.WebRootPath + @"\"; } } var repository = _fileSystemGenericRepositoryFactory.CreateFileRepositoryReadOnly(default(CancellationToken), searchPath, IncludeSubDirectories, SearchPattern); var data = await repository.GetAllAsync(LamdaHelper.GetOrderByFunc <FileInfo>(OrderByProperty, OrderByType), null, null); var results = new List <SelectListItem>(); foreach (var item in data) { IHtmlHelper html = context.CreateHtmlHelper((dynamic)item); results.Add(new ModelSelectListItem() { Model = item, Html = html, Text = RemoveSearchPathFromText ? context.Eval(html, item, DataTextFieldExpression).Replace(searchPath, "") : context.Eval(html, item, DataTextFieldExpression), Value = RootRelativeValue ? webFolder ? context.Eval(html, item, dataValueField).Replace(root, "").Replace(@"\", @"/") : context.Eval(html, item, dataValueField).Replace(root, "") : context.Eval(html, item, dataValueField), }); } return(results); }
protected override Task <IEnumerable <SelectListItem> > GetSelectListItemsAsync(SelectListContext context) { var results = new List <SelectListItem>(); for (int i = 0; i < _text.Length; i++) { IHtmlHelper html = context.CreateHtmlHelper((dynamic)_values[i]); results.Add(new ModelSelectListItem() { Model = _values[i], Html = html, Text = _text[i].ToString(), Value = _values[i].ToString() }); } return(Task.FromResult(results.AsEnumerable())); }