Pom*_*ter 43 c# asp.net-mvc file
我试图在MVC控制器中使用它之前查看文件是否存在:
string path = "content/image.jpg";
if (File.Exists(path))
{
//Other code
}
Run Code Online (Sandbox Code Playgroud)
该File
关键字以红色下划线,编译器显示错误:
System.Web.MVC.Controller.File(string, string, string)
是一种'方法',巫婆在给定的上下文中无效.
我如何File.Exists()
在控制器中使用?
Dar*_*rov 81
您应该在其前面加上命名空间:
if (System.IO.File.Exists(picPath))
{
//Other code
}
Run Code Online (Sandbox Code Playgroud)
原因是因为您在控制器操作中编写此代码,该控制器操作已File
在Controller类上定义了一个方法.
归档时间: |
|
查看次数: |
15512 次 |
最近记录: |