未生成区域中的 T4MVC MVC2 视图
我只是创建一个空的 MVC2 项目。添加一个区域、一个控制器和一个视图。将 T4MVC 文件包含到项目中并运行自定义工具。
除了区域中视图的视图名称之外,所有内容均已生成。
我的树结构:
Areas
- MyArea
- 控制器
- MyTestController.cs
- 浏览次数
- 我的测试
- MyTestView.aspx
- MySecondTestView.aspx
- 我的测试
- 控制器
如您所知,我可以直接在 Views 文件夹以及控制器命名的文件夹中查看视图。
有人经历过这样的事情吗?
I just create an empty MVC2 project. Add an Area and a controller and a view to it. Include T4MVC files into the project and run the custom tool.
Everything is generated except the ViewNames for the views in the Area.
My tree structure:
Areas
- MyArea
- Controllers
- MyTestController.cs
- Views
- MyTest
- MyTestView.aspx
- MySecondTestView.aspx
- MyTest
- Controllers
As you can I have views directly in Views folder and also in folders named by the controller..
Did anyone experienced something like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
T4MVC 绝对支持访问区域中的视图。我刚刚在一个新项目中尝试了以下操作:
之后,我'我可以写:
或
T4MVC definitely supports accessing the views in an Area. I just tried the following on a new project:
After that, I'm able to write either:
or
ASP.NET MVC 2 开箱即用,使用命名约定将视图链接到控制器操作。这些约定允许它找到控制器中操作的默认视图。
例如,MyTestController.cs 将具有操作。假设它只有一个,测试。
默认情况下,MVC 框架会在文件夹 MyArea/Views/MyTest 中查找名为 Test.aspx 的视图
,如果在那里找不到,则会在 /MyArea/Views/Shared 下查找名为 Test.aspx 的视图
,然后它将查找查看/视图/共享。
[我可能会丢失一个位置,我确信有 4 个位置,但不记得另一个位置了...无论如何,原则是成立的]
如果它在这些位置中的任何一个位置都找不到 Test.aspx,它就会抱怨。
您似乎正在与这些惯例作斗争。这会导致你陷入各种并发症。因此,最好阅读一本有关 MVC 的好书,真正了解 MVC 设计工作原理的基础知识。
ASP.NET MVC 2 works, out of the box, using naming conventions to link views to controller actions. These conventions allow it find default views for actions in a controller.
For example, MyTestController.cs will have actions. Lets say it only has one, Test.
By default, MVC framework will look for a view called Test.aspx in a folder MyArea/Views/MyTest
If it doesn't find it there, it will look for the view Test.aspx under /MyArea/Views/Shared
Then it will look in /Views/Shared.
[I might be missing one location, am sure there are 4, but can't remember the other one... Anyway, the principle stands]
If it can't find Test.aspx in any of those locations, it will complain.
You seem to be fighting these conventions. And that will lead you into all kinds of complications. So it is best to read a good book on MVC and really learn the basics of how MVC is designed to work.