0

I have question about .NET MVC, respectively about standards

I am doing an information system and have my business logic as separate project and also data access logic as another separate project

I did this like this for making further modificitaion more easier (like changing data source, the MVC I use in fact just for communication between C# and HTML), So the MVC project do not know about how the data are created, it just gets them from different project

So the model part in this MVC project is empty and will not contain any models

Is this aproach valid? Or should I use models in MVC in this scenario

David Watts
  • 2,249
  • 22
  • 33
Kerman
  • 29
  • 3

2 Answers2

1

I am doing information system and have my bussines logic as separate project and also data access logic as another separate project

Each project with different responsabilities; absolutely correct. Just be sure that Views has no access to your Business Logic (to avoid breaking the MVC pattern).

I did this like this for making further modificitaion more easier (like changing data source, the MVC I use in fact just for communication between C# and HTML)

You shouldn't think in a MVC project this way. You just moved your Model (M) wich has the Business logic. Now, your "MVC project" is the "UI project" wich has Controllers (C) as a way to communicate and Views (V) as a way to show data.

So the MVC project do not know about how the data are created, it just gets them from different project

This sentence should be: "Views do not know anything about the Model, and Controllers are used to interact with the Model". ¡This is just the MVC pattern!

Is this aproach valid? Or I should use models in MVC in this scenario

Your models folder will now be used to store Request and Response DTOs. However, is not mandatory. You can use dynamic objects, ViewBag objects to send data to the Views. Or not using the ASP.NET MVC framework Views and return JSON objects as Web Api does (ASP.NET Web Api also follows the MVC pattern).

Conclusion

When you create an ASP.NET MVC project, it is just a template that helps you to follow the MVC pattern, but you can change this template in several ways without breaking the MVC pattern.

Xavier Egea
  • 4,712
  • 3
  • 25
  • 39
0

Your models / viewmodels can be in another class library project as long as that project is referenced by your MVC project.

The following post debates the finer points of why you might choose to do this one way instead of the other:

ViewModel Best Practices

Community
  • 1
  • 1
David Tansey
  • 5,813
  • 4
  • 35
  • 51