viewmodel

Interaction of view models in MVVM

大憨熊 提交于 2019-11-28 04:46:17
I have a WPF application which follows the MVVM pattern. The application defines two views and view models so far: LoginView(Model) ProjectsView(Model) Both view models need to access several properties from other view models. Example: LoginViewModel has a property ProjectList . ProjectsViewModel needs to access this property as well. This is only a simple example. Later there will be several UserControls which all need to interact with each other. Would it be a better idea to create one huge view model which all UserControls (views) set as their DataContext ? If not, how can all the different

MVC 3 form post and persisting model data

a 夏天 提交于 2019-11-28 04:42:14
I think I'm missing some fundamentals on how MVC forms work. I have a search form on my home page that has five or six different fields a user can search on. So I have this POSTing to my results action just fine. The Result action looks like this: [HttpPost] public ActionResult Results(SearchModel model) { ResultsModel results = new ResultsModel(); results.ResultList = SearchManager.Search(model).ToList(); return View("Results", results); } I've simplified the above method for this post, but the idea is the same. So this all works fine. My results page shows up with the list of results and my

Using view models in ASP.NET MVC 3

浪尽此生 提交于 2019-11-28 04:34:43
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(); model.MapFrom(project); // Extension method using AutoMapper. return View(model); } If the screen

ValidateInput(false) vs AllowHtml

爱⌒轻易说出口 提交于 2019-11-28 04:19:14
I have a form that is used to create a memo, to do that I am using a rich text editor to provide some styling, this creates html tags in order to apply style. When I post that text, the mvc throws an error to prevent potentially dangerous scripts, so I have to specifically allow it. I have found 2 ways of doing this, one is to decorate the controller method with [ValidateInput(false)] and the other is to decorate the ViewModel attribute with [AllowHtml] . To me, [AllowHtml] looks much nicer, but I have only found that approach used 1 time and the [ValidateInput(false)] seems to be the

Android ViewModel additional arguments

陌路散爱 提交于 2019-11-28 03:39:21
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 user my custom ViewModel class I use this code in my fragment: MyViewModel myViewModel = ViewModelProvider

How to update LiveData of a ViewModel from background service and Update UI

邮差的信 提交于 2019-11-28 03:38:31
Recently I am exploring Android Architecture, that has been introduced recently by google. From the Documentation I have found this: public class MyViewModel extends ViewModel { private MutableLiveData<List<User>> users; public LiveData<List<User>> getUsers() { if (users == null) { users = new MutableLiveData<List<Users>>(); loadUsers(); } return users; } private void loadUsers() { // do async operation to fetch users } } the activity can access this list as follows: public class MyActivity extends AppCompatActivity { public void onCreate(Bundle savedInstanceState) { MyViewModel model =

what is difference between a Model and an Entity

夙愿已清 提交于 2019-11-28 03:33:52
I am confused to understand what is the meaning of this words: Entity , Model , DataModel , ViewModel Can any body help me to understanding them please? Thank you all. I hope I've not missed your point here king.net... Anyway, presuming you're talking about entity modelling or entity-relationship modelling (ERDs): an entity represents any real world entity - e.g. student, course, an entity will have attributes - e.g. student has first name, surname, date-of-birth an entity will have relationships - e.g. student "is enrolled on" course (where student and course are entities with attributes and

Flat vs Nested ViewModel Classes in ASP.NET MVC

随声附和 提交于 2019-11-27 19:40:29
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 IEnumerable<Country> Countries{ get; set; } .... } Flat ViewModel public class

EF Entities vs. Service Models vs. View Models (MVC)

Deadly 提交于 2019-11-27 19:17:01
问题 I'm trying to understand and figure good practices for designing your app/domain models (POCOs/DTOs). Let's say I have the following database table, Account: UserID int Email varchar(50) PasswordHash varchar(250) PasswordSalt varchar(250) Of course, EF4 would build the entity like so: public class Account { public int UserID { get; set; } public string Email { get; set; } public string PasswordHash { get; set; } public string PasswordSalt { get; set; } } Now, let's say I have a view model for

File upload bound to the Viewmodel

心已入冬 提交于 2019-11-27 18:14:52
问题 I have a form where I am uploading multiple files and there are a couple of textboxes and some checkboxes associated with each file being uploaded. I have seen examples for uploading multiple files where the actionresult signature is something like this: [HttpPost] public ActionResult Upload(IEnumerable<HttpPostedFileBase> fileUpload) However, I cant find any example where I can have multiple files uploaded where my actionresult signature is something like this: [HttpPost] public ActionResult