【发布时间】:2011-02-16 08:28:57
【问题描述】:
我只需要一个类似 CMS 的小型控制器。最简单的方法是这样的:
public class HomeController : Controller {
public ActionResult View(string name) {
if (!ViewExists(name))
return new HttpNotFoundResult();
return View(name);
}
private bool ViewExists(string name) {
// How to check if the view exists without checking the file itself?
}
}
问题是如果没有可用的视图,如何返回 HTTP 404?
也许我可以检查适当位置的文件并缓存结果,但感觉真的很脏。
谢谢,
德米特里。
【问题讨论】:
标签: .net asp.net-mvc asp.net-mvc-2 view http-status-code-404