viewmodel

What's the point of separating the Model from the View Model? (MVVM)

为君一笑 提交于 2020-02-15 08:20:02
问题 I don't think I understand the MVVM pattern properly because having a Model and ViewModel class seems redundant to me. My understanding of the Model is to basically add in minor details of a class and let the ViewModel handle all the logic and implementation. If that is the case why separate the two? Couldn't you create the variables, properties and such in the view model and still have the logic in there? To me it sounds like C++ in a way. You have the header file which describes the class

As ViewModelProviders.of() is deprecated, How should i create object of ViewModel?

扶醉桌前 提交于 2020-02-01 22:15:23
问题 I have been trying to create an Object of ViewModel in an Activity but ViewModelProviders is deprecated So what's the alternative to create the ViewModel's object. 回答1: Simply replace: This: boardViewModel = ViewModelProviders.of(this).get(BoardViewModel::class.java) With this: boardViewModel = ViewModelProvider(this).get(BoardViewModel::class.java) 回答2: ViewModelProviders.of() has been deprecated. You can pass a Fragment or FragmentActivity to the new ViewModelProvider(ViewModelStoreOwner)

As ViewModelProviders.of() is deprecated, How should i create object of ViewModel?

拥有回忆 提交于 2020-02-01 22:13:19
问题 I have been trying to create an Object of ViewModel in an Activity but ViewModelProviders is deprecated So what's the alternative to create the ViewModel's object. 回答1: Simply replace: This: boardViewModel = ViewModelProviders.of(this).get(BoardViewModel::class.java) With this: boardViewModel = ViewModelProvider(this).get(BoardViewModel::class.java) 回答2: ViewModelProviders.of() has been deprecated. You can pass a Fragment or FragmentActivity to the new ViewModelProvider(ViewModelStoreOwner)

ID Being Rendered As Null In A Typed Razor View

纵饮孤独 提交于 2020-01-25 09:48:23
问题 This is really weird, for some reason the Id of the ViewModel is being rendered as null inside the view. I debugged the application and checked that the view model is actually being mapped correctly (using AutoMapper) and everything is fine. But when I do @Model.Id, it is rendering as zero, and when I alert the value using jQuery I get "null". So what's going on? <div id="commentBox"> @using (Html.BeginForm("Comment", "Item", new { itemId = Model.Id } )) { <span class="greenText">answer</span

Replacing ViewModels with Tuples

醉酒当歌 提交于 2020-01-25 08:31:05
问题 I've just started on a new project which currently contains a fair few ViewModel DTO classes. I'm wondering whether it would be useful and even good practice to replace many of these DTOs with Tuples and to use that as my method of transfering a bunch of objects to my views. What do you think? Is this a correct usage of the tuple or am I off the mark here? 回答1: Usually view models have metadata associated with them which among other allows you to perform validation and integrates with editor

<android.arch.lifecycle.ViewModel>> cannot be provided without an @Provides-annotated method

杀马特。学长 韩版系。学妹 提交于 2020-01-24 09:20:13
问题 I am trying to create a viewmodel module like in this example but I am having this error error: java.util.Map,javax.inject.Provider> cannot be provided without an @Provides-annotated method. I followed all the example, here are my codes ViewModelFactory class @Singleton public class ViewModelFactory implements ViewModelProvider.Factory { private final Map<Class<? extends ViewModel>, Provider<ViewModel>> mCreators; @Inject ViewModelFactory(Map<Class<? extends ViewModel>, Provider<ViewModel>>

ObservableCollection CollectionChanged not helpful in WPF MVVM

空扰寡人 提交于 2020-01-24 08:59:06
问题 I am using a DataGrid and is bind using an ObservableCollection in the ViewModel private ObservableCollection<StockItem> _stockList; public ObservableCollection<StockItem> StockList { get { return _stockList; } set { _stockList = value; OnPropertyChanged("StockList"); } } The StockItem class contains its Properties which are the Column in DataGrid. There is a column named Amount in DataGrid whose values changed with Quantity*Price Column of the same datagrid. I have a Property called

WPF MVVM: How do ViewModels communicate with each other?

喜你入骨 提交于 2020-01-20 14:21:48
问题 I have a View which has 2 sub views on it and a ViewModel is assigned to each view: ViewA - ViewModelA { ViewB - ViewModelB ViewC - ViewModelC } ViewB has a text box and ViewC has a combobox, both of which i need access from ViewModelA. Not the GUI control itself, but the bound value i.e. .Text of the textbox and .SelectedItem of the ComboBox. Currently i just have ViewModelB and ViewModelC as properties on ViewModelA but it feels wrong. What's the standard way for view models to communicate

ASP.NET MVC 5, how to enable validation annotation on viewmodel that composes other view models?

末鹿安然 提交于 2020-01-17 11:15:51
问题 Well I have a very complex User Profile system in a social network application I am building. The profile page has tabs that distinguishes each category of user profile information: Basic, Education, Job. There is a UserProfileViewModel sitting on top of everything, which composes of inner view models such as BasicViewModel, EducationViewModel and JobViewModel. Consider the structure as below: public class ProfileViewModel { public string id { get; set; } public BasicViewModel basic { get;

How can I get a double from the View into My Model?

前提是你 提交于 2020-01-17 03:14:13
问题 This is weird and I'm being on this for a couple days with no more ideas. Even asked before with no results as well What's the way to add decimal number to SQL that replicate in EF? I have my simple Model like this public class SalesModelView { public int SaleId { get; set; } public int ShopId { get; set; } public DateTime SaleDate { get; set; } public int Hours { get; set; } public double Sales { get; set; } public double Treatments { get; set; } public double Turnover { get; set; } public