我想将azure blob存储容器名称显示为DropDownList的项目。我想使用ASP.NET和MVC
来做到这一点答案 0 :(得分:1)
使用WindowsAzure.Storage nuget包,以下代码可以获取blob存储中的容器列表:
public ActionResult Index()
{
// User your connection string in place of connectionString.
var storageAccount = CloudStorageAccount.Parse(connectionString);
// Create the blob client.
var blobClient = storageAccount.CreateCloudBlobClient();
// Get the list of containers from blob storage.
var containers = blobClient.ListContainers();
// Generate a MVC SelectList from the list of containers.
var listForView = new SelectList(containers, "Name", "Name");
// You can now attach this to your existing view model or just put it in a ViewBag and use it from there on your view
ViewBag.ContainersList = listForView;
return View();
}
从此处开始,您可以将通过ViewBag或视图模型创建的选择列表传递给View,然后将其与DropDownList助手一起使用。