What's the difference between Model, ViewModel and DTO? [closed] - asp.net-mvc

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I am an ASP.NET MVC developer and I am confused. What's the difference between Model, ViewModel and DTO (Data Transfer Object)? Is it ok for model to have methods that will save itself to database?

DTO is an object for passing data in case of communication between layers. It's a general pattern that is not tied to ASP.NET MVC.
ViewModel contains a data specific to particular view, is passed to that view in controller and is used in the view for rendering. It's a pattern specific to ASP.NET MVC (don't mix up with ViewModel from MVVM - they are different)
Model is a set of objects that represent your business domain. It can contain methods that will save it to DB depending of what pattern you will choose to build it (something like Active Record in your case).

Related

.NET MVC application into an N Tier application [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
In either .NET MVC 5 or a .NET Core MVC application, is it possible to split your Models into a Data Transport Layer, your business logic into a Business Logic Layer and your Db Contexts into a Data Access Layer? I essentially would want the main project to really only have controllers that call to the BLL, and display the results in the view. That way there is portability with my application if I wanted to exchange the main project, which is essentially just a presentation layer.
I know I am going to be needing this kind of architecture as I am building an application that will share a lot of the same business logic between the two applications. What ways can I still get access to helpful features like scaffolding a model into views/controller, and still maintain that portability? Is there a way to do such a thing?
Please note, that this project may be on a short budget, so it is pretty essential to be able to maintain the scaffolding tooling.

Best Data Access Technology in MVC4 and MVC5 [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am in confusion about the data access technology in mvc4 whether we should use Entity Framework or Linq or something else which is better than this ?
I have research much in this topic and not satisfied with all.?So can you help me about this with proper Detail?
The question will have answers upon user based opinions and experience.
This is what my personal recommendation is Model:
Take this as a Tree View Structure
1. Controller
2. ActionMethod //call the desired Factories
3.1 View Factory //to get data in DB
3.2 Domain Factory //to set data in DB
4. Services //Interface for Caching and top operations
5. Repositories //Contains on CRUD Operations
Inside the Repositories I would prefer LINQ-to-Entities rather than LINQ-to-SQL.
A great way of UNIT OF WORK PATTERN is being explained here

ViewModel in Asp.Net MVC vs Knockout.Js [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm really confused about how ViewModel works in the context of KnockOut.js and Asp.Net MVC.
In Asp.Net MVC, ViewModels are similar to DTOs. They are used to have strongly typed views. It is considered a good practice, which I've been abinding to as well.
However, recently I got interested in Knockout.js, which uses ViewModels in a whole different way. I'm still not 100% sure, but ViewModels are like Controllers it seems.
I guess I'm still confused about the ViewModel in knockout.js because its not the same as Asp.Net MVC. Can you please help clarify these two patterns?
You are correct. The logic in MVC is inside the controller and a view model in this context is basically a strongly-typed ViewBag or DTO for passing data to the view for one-way databinding.
In Knockout and anything on the XAML stack, a view model is more of a typical MVVM "view model" that is more like a controller that exposes observable properties for two-way databinding.

In ASP.NET MVC, why Model and View can talk to each other? does it break the concept of MVC? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
First of all, this is my first week on MVC 4
Microsoft claims the MVC will be the best web coding solution in the future based on three level framework.
1.Yet in their MVC concept, view and model can talk without controller, can any body tell me why they made that like a circle? What's the benefit behind it?
2.Without the view_state in web form, how can I know if a page is a post back?
Any open-mind ideas are welcomed!
1.Yet in their MVC concept, view and model can talk without controller, can any body tell me why they made that like a circle?
What's the benefit behind it?
View and Model cannot talk without controller. Your view would never have known the Model if the Controller hasn't passed it to.
2.Without the view_state in web form, how can I know if a page is a post back?
Why would you even want to know such thing? This is an artificial concept invented specifically for classic WebForms to alleviate the stateless nature of the HTTP protocol and make Web development ressemble Desktop development. In an MVC application you never need to know anything like that.

Is using ViewBag in MVC bad? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
It seem like mvc 3 team decided to bring in a feature for dynamic data exchange between a controller and a view called the viewbag but it is A good thing against the strongly typed view we all know about? What are some of the positive and negative aspects to using the ViewBag versus using a strongly typed view?
The ViewBag is the same thing as ViewData in previous ASP.NET MVC 1 and 2. It just happens to be dynamic instead of needing to use it like a dictionary with keys. I don't think this will replace strongly typed views at all and in fact you should use Viewdata/Viewbag as little as possible. Always use strongly typed views whenever possible since it will lead to fewer errors if the names in your Viewdata/Viewbag change and make the HTML cleaner by not having ViewData casts all over the place.

Resources