在 asp.net mvc3 中返回特定视图时出现问题
我有一个像这样的视图文件结构:
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);
}
}
但是控制器给了我一个错误 - 告诉我它找不到视图。这些是它搜索的路径。
~/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
基本上,如果我能够消除 Employee 部分,引擎就会找到它。
~/Views/Employee/Company/Employee/ManageEmployee.cshtml 对此
~/Views/Company/Employee/ManageEmployee.cshtml
有关如何实现此目标的任何见解。
谢谢。
I have a view file structure like:
Views
Company
Department
Employee
ManageEmployee.cshtml
and the controller is
public class EmployeeController : Controller
{
public ActionResult Index(int dptId)
{
var loadedEmp = getEmpOf(dptId);
return View("Company/Employee/ManageEmployee", loadedEmp);
}
}
But the controller give me an error - telling that it can't find the view.These are the paths it search.
~/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
Basically if I'm able to eliminate the Employee section, the engine will find it.
~/Views/Employee/Company/Employee/ManageEmployee.cshtml to this
~/Views/Company/Employee/ManageEmployee.cshtml
Any insights on how to achieve this.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否尝试过:
看起来引擎正在尝试返回相对于您在站点中当前位置的视图,而不是从站点的根目录返回视图。
Have you tried:
It looks like the engine is trying to return the view relative to your current location in the site rather than from the root of the site.
视图必须通过以下方式从控制器返回(对于特定视图):
在 MVC 中,控制器将自动路由到您提供的视图名称。
loadedEmp
应该是您传递给视图的对象。View has to be returned from the controller in the following way (for Specific View):
In MVC, the controller will automatically route to the View name you provided.
loadedEmp
should be the object you are passing to the view.您需要遵循控制器的 MVC 约定 ControllerNameController 以及 ControllerName/ 的视图结构...
如果您想完全控制您的结构,您需要切换到不同的框架,例如 FubuMVC。
You need to follow MVCs convention of ControllerNameController for your controller and your view structure of ControllerName/...
If you want full control over your structure you'll need to switch to a different framework like FubuMVC.
如果您想要自己的视图文件夹结构安排惯例,最好插入您自己的视图引擎。
If you want your own convention of arranging the views folder structures, it would be better you plug in your own view engine.