Answer the question
In order to leave comments, you need to log in
How to generate a view model from a domain model in ASP.NET MVC?
Good day to all, I ran into a problem, it is necessary to display, using the view model, brief information about the announcement of the car.
There are entities in the domain model, BrandAuto, ModelAuto, SpecificaAuto, AdvertisingAuto. - this is all a domain model, they are interconnected - "one to many" and have their own fields, of course I do not need all these fields for presentation.
How can I create a ViewModel that would display:
Answer the question
In order to leave comments, you need to log in
Hello Michael again! In general, less words - more code. Toster_q187249.zip - here is the archive with the application. I modeled the subject area as I understood :)
To be honest, I have never heard the phrase "domain model". Where does this term come from? Usually, the terms "data", "model" are used to describe data.
Next: Read from cover to cover " ASP.NET MVC 3/4 Framework with C# Examples for Professionals " by Adam Freeman, Steven Sanderson. For MVC - in my opinion, this is the #1 book for learning ASP.NET MVC. Everything you need is there, and even more. You, however, may have difficulties with the Entity Framework, because there they do not explain in such detail how to work with it (the authors probably count on a little experience of the readers with this framework). After reading, everything will fall into place in your head.
There will be some questions about the project - write. It is, of course, primitive, but for learning purposes, in my opinion, it will do.
You probably already know, but, nevertheless, I will write: the controller should have a minimum of business logic. The controller should only receive data from somewhere, form a view model from it and give the view model to the view itself. All the logic of working with data should be placed in a separate layer (for example, in a separate dll). All business logic, for good, should also be placed in a separate layer. As a result, the controllers of the MVC application must “break” into the business logic layer, which, in turn, breaks into the layer for working with data, pulls them out, processes them and gives them “upstairs” to the client application (MVC-application). This allows you to create a three-level solution architecture and thereby create more scalable and flexible applications.
For example, the application that I sent you consists of 2 layers:
1) MVC-app;
2) Core.DAL - layer for working with data.
Ideally, you should add a new layer (for example, Core.BL or Core.BAL) - a layer of business logic.
Here's just in case:How to organize the architecture of the Project Management System applications?
Good luck in our hard work!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question