我想将azure blob存储容器名称显示为DropDownList的项目。我想用ASP.NET和MVC来做这件事
使用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帮助器一起使用。