我有这样一个视图文件结构:

Views
   Company
      Department
      Employee
          ManageEmployee.cshtml

和所述控制器

public class EmployeeController : Controller
 {
    public ActionResult Index(int dptId)
    {
            var loadedEmp = getEmpOf(dptId);
            return View("Company/Employee/ManageEmployee", loadedEmp);
     }
}

但控制器给我一个错误 - 告诉它不能找到view.These是它搜索的路径

~/Views/Employee/Company/Employee/ManageEmployees.aspx
~/Views/Employee/Company/Employee/ManageEmployees.ascx
~/Views/Shared/Company/Employee/ManageEmployees.aspx
~/Views/Shared/Company/Employee/ManageEmployee.ascx
~/Views/Employee/Company/Employee/ManageEmployee.cshtml
~/Views/Employee/Company/Employee/ManageEmployee.vbhtml
~/Views/Shared/Company/Employee/ManageEmployee.cshtml
~/Views/Shared/Company/Employee/ManageEmployee.vbhtml

基本上,如果我能够消除在员工部分,引擎会发现它。

〜/查看/ <强>员工 /Company/Employee/ManageEmployee.cshtml 以这

〜/查看/公司/雇员/ ManageEmployee.cshtml

上任何见解如何实现这一点。

感谢。

有帮助吗?

解决方案

您需要按照ControllerNameController的MVCS约定控制器和ControllerName /...

如果你想完全控制你的结构你需要切换到如 FubuMVC

其他提示

你试过:

return View("/Company/Employee/ManageEmployee", loadedEmp);

它看起来像引擎正试图视图相对于在该网站,而不是从网站的根返回到您当前的位置。

查看必须从以下面的方式将控制器返回(用于特定视图):

return View("ManageEmployee", loadedEmp);

在MVC中,控制器将自动路由到您提供的视图名。

loadedEmp应该是要传递到该视图的对象。

如果你想自己整理文件夹结构的意见的惯例,倒不如你在自己的视图引擎插件。

scroll top