正如标题所说,我试图通过这种方式将外部图像循环显示在ASP.NET MVC 4网络应用程序中的一个视图中:
for(int i= 1; true; i++){
string filepath = "C:\imgs\" + i + ".png";
do{
bool exists = filepath.exists;
} while(!exists);
displayImage(filepath);
}
请问如何处理?
答案 0 :(得分:0)
// 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 />
}