viewmodel

Why Two Classes, View Model and Domain Model?

筅森魡賤 提交于 2019-11-27 00:52:51
I know it could be bad to use domain models as view models. If my domain model has a property named IsAdmin and I have a Create controller action to create users, someone could alter my form and get it to POST a IsAdmin=true form value, even if I did not expose such a text field in my view. If I'm using model binding then when I committed my domain model, that person would now be an admin. So the solution becomes exposing just the properties I need in the view model and using a tool like AutoMapper to map the property values of my returning view model object to that of my domain model object.

Using view models in ASP.NET MVC 3

拈花ヽ惹草 提交于 2019-11-27 00:31:00
问题 I'm relatively new to view models and I'm running into a few problems with using them. Here's one situation where I'm wondering what the best practice is... I'm putting all the information a view needs into the view model. Here's an example -- please forgive any errors, this is coded off the top of my head. public ActionResult Edit(int id) { var project = ProjectService.GetProject(id); if (project == null) // Something about not found, possibly a redirect to 404. var model = new ProjectEdit()

Android ViewModel additional arguments

喜你入骨 提交于 2019-11-26 23:59:41
问题 Is there a way to pass additional argument to my custom AndroidViewModel constructor except Application context. Example: public class MyViewModel extends AndroidViewModel { private final LiveData<List<MyObject>> myObjectList; private AppDatabase appDatabase; public MyViewModel(Application application, String param) { super(application); appDatabase = AppDatabase.getDatabase(this.getApplication()); myObjectList = appDatabase.myOjectModel().getMyObjectByParam(param); } } And when I want to

Bestpractice - Mixing View Model with Domain Model

女生的网名这么多〃 提交于 2019-11-26 23:36:39
问题 Is it reasonable to mix view models with domain models? So i.e. the view model object contains some domain model objects (not the other way around!) 回答1: Generally, you will have to reference your Domain Models in your View Models, or at least load the Domain Models in the controllers and pass the information on to your View Model. I prefer to keep Controllers and Views as simple/dumb as possible, because both Domain Models and View Models are FAR easier to test. So, I often reference my

Accessing a property in one ViewModel from another

懵懂的女人 提交于 2019-11-26 21:53:09
问题 I want main viewmodel to have a certain list, and then access from many other viewmodels. For example, in MainViewModel.cs I will have a list of 50 numbers, then in NumListViewModel.cs, I'd like to access it in order to show it as a list, and in AddNumViewModel.cs I'd like to be able to update that list. It's been suggested that I use events / evenaggerator, which I did, but unfortunately, for all I know all I can do with it is send a num from one view to another and tell it to update the

ASP.Net MVC 3 Retrieve Checkbox List Values

浪尽此生 提交于 2019-11-26 21:22:29
问题 I am developing an ASP.Net MVC 3 Web application and I am having some difficulties with getting the values from a checkboxlist. I have already read most of the questions on Stackoverflow around this area, however, I am still having some issues. I have a ViewModel public class ViewModelCheckBox { public string Id { get; set; } public string Name { get; set; } public bool Checked { get; set; } } Another ViewModel which use the viewmodel above public class ViewModelAssignSubSpeciality { public

Flat vs Nested ViewModel Classes in ASP.NET MVC

时光毁灭记忆、已成空白 提交于 2019-11-26 20:08:27
问题 I'm looking for some opinions on two different approaches to ViewModel definition I have a Company class public class Company { public string Name { get; set; } public int CountryID { get; set; } } For the Create and Edit views I need a list of Countries to populate a DropDownList for CountryID selection. I can see two broad choices for how to structure the ViewModel that are detailed below. Nested ViewModel public class CompanyCreateEditViewModel { public Company Company { get; set; } public

How to write a ViewModelBase in MVVM

橙三吉。 提交于 2019-11-26 19:02:30
问题 I'm pretty new in WPF programming environment. I'm trying to write a program out using MVVM design pattern. I've did some studies and read up some articles related to it and many of a time I came across this thing called ViewModelBase I know what it is.. But may I know specifically where should I begin with to be able to write out my own ViewModelBase? Like... Really understanding what's happening without getting too complicated. Thank you :) 回答1: It's worth nothing to use MVVM frameworks if

ASP.NET MVC ViewModel Pattern

随声附和 提交于 2019-11-26 18:50:47
EDIT: I made something much better to fill and read data from a view using ViewModels , called it ValueInjecter . http://valueinjecter.codeplex.com/ it is used by http://prodinner.codeplex.com - an ASP.net MVC sample application you can see the best way of using ViewModels in prodinner using the ViewModel to store the mapping logic was not such a good idea because there was repetition and SRP violation, but now with the ValueInjecter I have clean ViewModels and dry mapping code That's the old stuff, don't use it: I made a ViewModel pattern for editing stuff in asp.net mvc this pattern is

DTO = ViewModel?

為{幸葍}努か 提交于 2019-11-26 18:49:22
问题 I'm using NHibernate to persist my domain objects. To keep things simple I'm using an ASP.NET MVC project as both my presentation layer, and my service layer. I want to return my domain objects in XML from my controller classes. After reading some posts here on Stack Overflow I gather DTOs are the way to go. However, I've also come across posts talking about the ViewModel. My question: Are Data Transfer Objects and ViewModels the same thing? Or is a ViewModel a kind of sub pattern of a DTO?