为什么我不能用有System.IO.File方法在MVC控制器? [英] Why can't I use System.IO.File methods in an MVC controller?
本文介绍了为什么我不能用有System.IO.File方法在MVC控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想看看一个文件中的MVC控制器,使用它之前存在:
I am trying to see if a file exists before using it in an MVC controller:
string path = "content/image.jpg";
if (File.Exists(path))
{
//Other code
}
的文件
关键字红色下划线,编译器显示错误:
The File
keyword is underlined in red, and the compiler shows an error:
System.Web.MVC.Controller.File(字符串,字符串,字符串)
是一个
方法,巫是不是在给定的范围内有效。
System.Web.MVC.Controller.File(string, string, string)
is a 'method', witch is not valid in the given context.
如何使用 File.Exists()
在控制器?
推荐答案
您应该preFIX它与命名空间:
You should prefix it with a namespace:
if (System.IO.File.Exists(picPath))
{
//Other code
}
这其中的原因是因为你写这code这已经定义的 文件
在控制器类方法。
The reason for that is because you are writing this code inside a controller action which already defines a File
method on the Controller class.
这篇关于为什么我不能用有System.IO.File方法在MVC控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文