如何在循环中显示来自web应用程序项目的外部图像
本文关键字:应用程序 web 项目 图像 外部 循环 显示 | 更新日期: 2023-09-27 17:54:57
正如标题所说,我试图在ASP中的一个视图中循环显示外部图像。. NET MVC 4 web-app,在这种方式:
for(int i= 1; true; i++){
string filepath = "C:'imgs'" + i + ".png";
do{
bool exists = filepath.exists;
} while(!exists);
displayImage(filepath);
}
请问该如何处理?
// model
class RenderImageModel
{
List<string> UserImages {get;set;}
public RenderImageModel(){
UserImages = new List<string>();
}
}
// controller action
public ActionResult Index(){
var model = new RenderImageModel();
for(int i= 1; true; i++){
string filepath = "C:'imgs'" + i + ".png";
do{
bool exists = filepath.exists;
} while(!exists);
model.UserImages.Add(filepath);
}
return View(model);
}
// view
@foreach(imagePath in Model.UserImages){
<img src='@imagePath' alt />
}