1

偶然发现了我研究过的一个好奇心,但没有找到任何确切的答案。我正在向我的 mvc 项目添加一个视图,当我注意到在提到视图的模型时,很多类似乎我没有直接的参考。例如,我可以在添加视图对话框中看到所有用于 excel 的 ClosedXml 类,但该 dll 在我的 Bussines Logic 项目中被引用,而不是在 Web 项目中肯定。那么 1. 为什么它会出现在添加视图对话框的模型下拉列表中?2.这个列表不应该只由模型文件夹中的类组成吗?对不起,如果这是一个愚蠢的问题,但没有人可以给我一个直接的答案。

4

2 回答 2

5

作为当前解决方案一部分的所有公共类都出现在此列表中,而不仅仅是那些在当前程序集的 Model 文件夹中声明的公共类。甚至引用程序集中的类也会出现。一些类将被过滤掉:

  • 以结尾的类型Controller(以避免在列表中看到您的控制器)
  • System在orMicrosoft命名空间中声明的类型
于 2012-07-22T13:25:25.970 回答
1

Besides of the answer of @DarinDimitrov

For example i can see in the add view dialog all the ClosedXml classes for excel but that dll is referenced in my Bussines Logic project

It seems Visual Studio iterates over all your references, so I assume you do have a reference to your business component in your MVC project

Now the reason?, well that's because you could practically use any public entity as your model

2.Should this list not be composed only of classes from the models folder?

NO

A model in MVC is a simple class to represent your view, please do not get confused about your current Domain Model. They used the same term but a model in MVC is just that, a simple class to represent your view and NOTHING MORE

With that in mind, you could use any public class as your model.

I think that's the reason behind although, I rarely use that option in Visual Studio because often it takes too much time to display the content of the list, so I prefer to set the model manually

于 2012-07-22T13:36:48.833 回答