简体   繁体   English

无法从ASP.NET MVC 3中的引用程序集中的模型添加强类型视图

[英]Can't Add Strongly-Typed View With Model From Referenced Assembly in ASP.NET MVC 3

I have a solution with an ASP.NET MVC 3 project, and a class library project. 我有一个ASP.NET MVC 3项目和一个类库项目的解决方案。 I created a reference to the class library, "Commands", in the web project, which is resolving; 我在要解决的Web项目中创建了对类库“ Commands”的引用。 copy-local is also set to true and Commands.dll is being copied into the web project's bin directory. copy-local也设置为true,并将Commands.dll复制到Web项目的bin目录中。

When I try to add a strongly-typed view, selecting a class from Commands as the model, I receive a "Could not load file or assembly" error for the Commands assembly. 当我尝试添加强类型视图时,从Commands中选择一个类作为模型,我收到Commands程序集的“无法加载文件或程序集”错误。

I've tried removing and re-adding the reference, cleaning and rebuilding the solution, etc. but still have the problem. 我试过删除并重新添加参考,清理和重建解决方案等,但是仍然有问题。

Something else odd about this is that when I click "Add view" in the controller to get to the add view dialog, the model in the referenced assembly is available in the "Model class:" drop-down. 对此还有些奇怪的是,当我在控制器中单击“添加视图”以进入“添加视图”对话框时,在“模型类:”下拉列表中可以找到被引用程序集中的模型。

Try using the Fully qualified name for the model class in your view. 尝试在视图中使用模型类的完全限定名称。

Ex : @model YourClassLibraryNameSpace.YourClassname 例如: @model YourClassLibraryNameSpace.YourClassname

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET MVC 3强类型视图:为什么在VS编辑器中未打开视图时,为什么编译器错误消失/被忽略? - ASP.NET MVC 3 Strongly-typed Views: Why do compiler errors disappear/are ignored when a view is not open in VS editor? 尽管已正确引用,但未找到强类型的程序集 - Strongly-typed assembly not being found despite being correctly referenced Visual Studio 2010 ASP.NET MVC:创建不显示我的类的强类型视图 - Visual Studio 2010 ASP.NET MVC: Create Strongly Typed View Not Showing My Classes T4MVC-具有模型绑定的操作-如何将完全限定的强类型URL字符串获取到另一个Controller? - T4MVC - Actions with model binding - how to get a fully qualified strongly-typed URL string to another Controller? ASP.Net构建错误 - 未引用程序集 - ASP.Net build error - assembly not referenced 基于自定义模型创建强类型视图 - Creating a strongly typed view based on a custom model 在ASP.NET MVC 3中添加视图时缺少模型类 - Missing model class when adding a view in ASP.NET MVC 3 使用ViewModel时,asp.net MVC“添加视图”向导不会预填充字段 - asp.net MVC “Add View” wizard won't pre-populate fields when using a ViewModel ASP.NET MVC 添加视图对话框关闭 - ASP.NET MVC Add View Dialog closing 找不到名称空间(ASP.NET MVC 3) - Can't find namespace (ASP.NET MVC 3)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM