我需要组合框中的图片,但我只有路径
var files = Url.Content("~/Content/skin/Simple.png");
@(Html.Telerik().ComboBox()
.Name("ComboBox")
.BindTo(files.Select(f => new SelectListItem { Selected = false, Text = f.ToString(), Value = "" }))
)
谢谢,但如果我需要显示文件夹中的所有图片
string searchFolder = Url.Content("~/Content/skin/");
var filters = new[] { "jpg", "jpeg", "png", "gif", "tiff", "bmp" };
var files = Some Class.GetFilesFrom(searchFolder, filters, false);
有我的完整代码
控制器
public ActionResult Combo()
{
return View();
}
模型
public class Combo
{
public static string[] GetFilesFrom(string searchFolder, string[] filters, bool isRecursive)
{
var filesFound = new List<String>();
var searchOption = isRecursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
foreach (var filter in filters)
{
filesFound.AddRange(Directory.GetFiles(searchFolder, String.Format("*.{0}", filter), searchOption));
}
return filesFound.ToArray();
}
}
和查看
@using TETRA.RS.WWW.UI.Models
@{
string searchFolder = Url.Content("~/Content/skin/");
var filters = new[] { "jpg", "jpeg", "png", "gif", "tiff", "bmp" };
var files = Combo.GetFilesFrom(searchFolder, filters, false);
}
@(Html.Telerik().ComboBox()
.Name("ComboBox")
.BindTo(files.Select(f => new SelectListItem { Selected = false, Text = f, Value = "" }))
)
我在组合框中只看到完整路径而且我不知道一个文件夹中有多少张图片