ASP.NET MVC - 如何从引用的类库中的类创建强类型视图?
我正在尝试使用 Visual Studio 2008 创建强类型视图。我可以右键单击控制器操作并选择:添加视图... 在下一个对话框窗口中,有一个选项“创建强类型视图”。 如果选中此选项,我可以选择当前项目中的类列表。
但是,我无法选择我引用的类库中所需的类。
- 类库是一个强类型程序集,加载在 GAC 中。
- 显然项目中引用了该库。
- 我添加了一个
在 web.config 中 - 我已经重建了多次,并且重新启动 VS
- Classlibrary 没有任何问题...
有什么建议吗?
i'm trying to create a strongly-typed view using Visual Studio 2008. I can right-click a controller action and choose: Add view... In the next dialog window there is an option 'Create a strongly-typed view'. If I check this option I can select a list of classes that are in my current project.
However I cannot select the class I need which is in a class-library that I referenced.
- The classlibrary is a strongly-typed assembly which is loaded in the GAC.
- Obviously the library is referenced in the project.
- I've added a <add namespace="namespace" /> in web.config
- I've rebuilt multiple times, and restarted VS
- Classlibrary doesn't have any problems...
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
对于回答这个问题来说肯定已经太晚了,但是对于未来的读者:
我注意到我经常必须构建->清理解决方案,然后构建->重建解决方案,并且类神奇地出现(正如它们应该的那样)
This is surely to late for answering this question,but for future readers:
i noticed that very often i have to build->clean solution and then to build->rebuild solution and the classes magically appear (as they should)
只需使用任何模型类创建视图,然后手动编辑 ASPX 并将模型类替换为您想要的模型类。 可能对话窗口不够智能。
但在我个人看来,使用“外部”类作为模型是非常错误的。
所有模型、视图和控制器都应该直接在您的项目中。 然后,他们可以在内部使用任何他们需要的东西,无论它在哪里。
Just create you view with any of the model classes then manually edit ASPX and replace the model class with the one you want. Probably the dialog window is just not intelligent enough.
But in my personal opinion, using "outside" classes as your models is very wrong.
All models, views and controllers should be here, directly in your project. They then can use internally whatever they need wherever it is.
这是很久以前发布的,但我的解决方案可能会帮助某人......
我刚刚遇到了同样的问题,我发现如果我有“Controller”作为类名的一部分 - 我有一个“DoorController” - 我不能通过强类型视图选择添加它。 这也给我带来了asp mvc的其他问题。
这对于“模型”和“视图”也可能适用吗? 尝试更改模型的类名称来解决此问题。
This was posted a long time ago but my solution might help someone....
I just had this same problem and I found that if I had "Controller" as part of the class name - I had a "DoorController" - I could not add it via the strongly-typed view selection. It also caused me other problems in asp mvc.
This might hold true for "Model" and "view" also? Try changing your model's class name to fix this issue.
我不确定我自己的类是否出现在列表中 - 我通常只是键入它们(从根命名空间开始)。 如果您尝试在文本框中输入例如
MyRootNamespace.MyClassLibrary.MyNamespace.AnotherNamespace.TheClass
并单击“确定”,会发生什么情况?I'm not sure if my own classes show up in the list or not - I usually just type them (starting from the root namespace). What happens if you try to type in for example
MyRootNamespace.MyClassLibrary.MyNamespace.AnotherNamespace.TheClass
in the textbox and click OK?我的自定义创建的数据类也遇到同样的问题。 它们显示在“查看数据类”下拉列表中,但“查看内容”下拉列表被禁用。 我猜我的类需要实现一些接口。 我只是不确定是哪一个。
I'm having the same problem with my custom-created Data Classes. They show up in the "View Data Class" drop down but the "View Content" drop down is disabled. I'm guessing that my classes need to implement some interface. I'm just not sure which one.