T4MVC 未获取区域中的视图 (ASP.NET MVC 3 RTM)
除了区域之外,T4MVC 在任何地方都运行良好。
在区域中,它获取控制器和操作,但不获取视图。
因此,我无法在我的控制器中写入:
return View(MVC.MyArea.MyController.Views.MyView);
在区域之外,我可以写入:
return View(Views.MyOtherView);
我还可以引用我的区域控制器中的操作:
MVC.MyArea.MyController.MyAction()
换句话说:
a。我可以获得任何我想要的东西,即使它不在某个区域。
b.我可以在我的区域控制器中获取操作。
c.但我无法获得我所在区域的观点。
问题可能是什么?
TIA
编辑:
问题是让 T4MVC 重新运行(请参阅 David Ebbo 的答案和我的“答案”)。
T4MVC is working fine everywhere except in Areas.
In Areas, it picks up the Controllers and the Actions, but not the Views.
So, I cannot write, in my controller:
return View(MVC.MyArea.MyController.Views.MyView);
Outside of the Areas, I CAN write:
return View(Views.MyOtherView);
I can also refer to actions in my area controllers:
MVC.MyArea.MyController.MyAction()
In other words:
a. I can get anything I want, if it is not in an Area.
b. I can get at the Actions in my Area controllers.
c. But I CANNOT get my Views in my Area.
What could the problem be?
TIA
EDIT:
The issue is getting T4MVC to rerun (see David Ebbo's answer and my "answer").
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你所拥有的应该可以工作,我通过以下方式验证了它:
之后,我可以编写:
或
请注意,在第二种情况下,“My”中的令牌而不是“MyController”,这是它始终工作的方式。
请尝试在干净的应用程序中执行这些步骤,看看它是否有效。
What you have should work, and I verified it by:
After that, I'm able to write:
or
Note that in the second case, the token in 'My' instead of 'MyController', which is the way it always works.
Please try following those steps in a clean app to see if it works.
我相信我的问题是由 T4MVC 未重新运行引起的。因此(我推测)T4MVC 不会更新以反映项目中的更改。例如,更改控制器中操作的参数。或者(特定于这个问题)添加一个新视图。
T4MVC 文档中有关重新运行的内容含糊其辞,但指出了一个名为 Chirpy 的 VS 添加。
Chirpy 安装完毕,然后您必须进行配置。您可以通过打开 Visual Studio,然后转到“工具>>”来执行此操作。选项并选择 Chirpy 选项。
请参阅图片:
我必须添加模板名称 T4MVC.tt 位才能使其正常工作。不确定这是否有必要或为什么。但现在一切都运转良好。
如果有更好的方法,请告诉我。
I believe my issue is being caused by T4MVC not rerunning. As a result (I speculate) the T4MVC does not update to reflect changes in your project. For example, changing the parameters of an Action in a Controller. Or (specific to this question) adding a new View.
The T4MVC documentation on getting itself to rerun is vague, but points you at a VS add in called Chirpy.
Chirpy installs, and then you have to go in an configure it. You do this by opening Visual Studio, then going to Tools >> Options and choosing the Chirpy option.
See the image:
I had to add the template name T4MVC.tt bit to get it to work. Not sure if this is necessary or why. But it all now works fine.
If there is a better way of doing this, please let me know.