C# MVC - 文件夹结构 - 在哪里放置类?
在asp/net MVC中,项目分为模型、视图和控制器。到目前为止还好。
假设我有一个类“person”,人员控制器使用人员模型向其中填充数据。
我的 person.cs 类最好放在哪里?在控制器或模型文件夹中?你做什么工作?
谢谢
弗兰克
In asp/net MVC, the project is divided into Models, Views and Controllers. Fine so far.
Say I have a Class 'person', which the people controller populates with data, using the person model.
Where is it best to put my person.cs class? In the controllers or the models folder? What do you do?
Thanks
Frank
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将在解决方案中创建另一个类库项目,定义我的类,然后在 ASP.Net MVC 应用程序中引用我的库。
I'd create another class library project in the solution, define my classes and then reference my library in my ASP.Net MVC application.
我会将 Person 视为模型并将其放在 Models 文件夹中。这是我保存视图模型的地方。业务模型通常保存在一个单独的数据项目中——我喜欢我的数据层是独立的,这样如果我愿意,我可以在其他项目中使用它。您可能需要考虑为其他类型的类(不适合控制器或模型类别的扩展方法、帮助程序等)创建单独的类库。
I would consider Person a model and put it in the Models folder. This is where I keep my view models. Business models are normally kept in a separate data project -- I like my data layer to be self-contained so I can use it in other projects if I want. You might want to consider creating separate class libraries for other types of classes -- extension methods, helpers, etc. that don't fit into the category of controllers or models.
目前在相当大的项目中工作,我将我的类分为不同的类库项目,这些项目名为 Repository(用于数据访问接口和业务数据类)、Utils(用于实用程序类)和 DataAccess(存储库接口实现)。在这些目录下,我将它们划分为子目录(或者我应该说命名空间),然后使用 Resharper 来强制执行这些命名空间。
Currently working at rather large project, I have my classes divided into different class library projects which are named Repository (for data access interfaces and business data classes), Utils (for utility classes) and DataAccess (repository interfaces implementations). Under those I have them divided in subdirectories (or should I say namespaces) and then use Resharper to enforce those namespaces.