viewmodel

Is it a bad practice using model classes in controller in mvc?

主宰稳场 提交于 2019-11-30 05:22:35
问题 I wanted to compare with best practices when working with an ORM or database tables in asp.net mvc. One of the major questions I have is should I instantiate the model classes directly in controller..not query the database but just use the model class to store the values. For e.g. If I am using entity framework as model...then is it a bad practice to use the entity class objects in the controller . There are times when it is just easier to directly use the database classes generated in the

Where to create parametrized ViewModel?

故事扮演 提交于 2019-11-30 05:22:13
I have recently parametrized my ViewModel's contructor. Before that, I was doing this in my window: <Window.DataContext> <vm:MyViewModel /> </Window.DataContext> The framework instantiated the ViewModel for me. I know I can set DataContext in code but I would prefer a XAML way so designer can display my test data when designing. Is this possible? Use an ObjectDataProvider if you want to specify constructor parameters: <Window.DataContext> <ObjectDataProvider ObjectType="vm:MyViewModel" xmlns:sys="clr-namespace:System;assembly=mscorlib"> <ObjectDataProvider.ConstructorParameters> <sys:String>A

difference between models and view models

夙愿已清 提交于 2019-11-30 05:21:35
I have been researching asp.net MVC project structure's for a new project and have a question about something is confusing me. What is the difference between models and view models? Would I be correct in saying that view models encompass models in the form properties? I've a blog where I want to display the list of the latest posts , latest comments , post categories in a single view. How I can do that? I can strongly type my view to any one of the model right? There comes view model . I created a view model called BlogViewModel that contains latest posts, latest comments and other stuff as

MVVM (with WPF) - Binding Multiple Views to the Same ViewModel

浪尽此生 提交于 2019-11-30 05:11:44
I have recently started investigating the MVVM pattern with WPF for an upcoming project. I started with Josh Smith's MSDN article. I have a question (well many, but let's start with one): I have an IndividualViewModel which exposes the properties of the model. I need two views "Add Individual" and "Edit Individual" which are very similar as you can imagine. What I have done currently is to have 2 subclasses AddIndividualViewModel and EditIndividualViewModel which expose the Add and Edit commands respectively. I also have 2 similary named views that bind to these. Now this method works and

Updating a viewmodel from another viewmodel

懵懂的女人 提交于 2019-11-30 04:14:15
问题 I have two ViewModels one is attached to a main window and the other is attached to child window that is opened by clicking on a button on the main window. The child window contains a list of items and I want to select an item and display it in the main window by updating the main window viewmodel. What is the best way to accomplish this. Thanks! 回答1: There are any number of ways to do this. Pass a reference to the main/parent view model into the child and have the child call the main view

WPF MVVM: How do ViewModels communicate with each other?

喜欢而已 提交于 2019-11-29 23:35:32
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 with each other without breaking the MVVM pattern? One way to have disconnected ViewModels communicate

EditorFor collection of items in my model

让人想犯罪 __ 提交于 2019-11-29 23:05:27
My ViewModel has a property that is a collection of another of my model entities, in this case CategoryTags (and each tag has a Tag and an ID). 1) Am I correct in understanding that Html.EditorFor() doesn't have an UI it can create for an ICollection? 2) Assuming #1, I've decided to make an EditorTemplate that is a textbox where my user can key in comma-separated tag names and jquery will autocomplete. Will I have to pass back the list of tag names (or their respective IDs) and then parse them back into the CategoryTags propety on POST? Thanks! Correct - you need your own template (See http:/

Domain vs DTO vs ViewModel - How and When to use them?

牧云@^-^@ 提交于 2019-11-29 20:19:24
In a Multi-layer project with Domain layer (DL)/Business (Service) Layer (BL)/Presentation Layer (PL), what is the best approach to deliver Entities to the Presentation Layer? DO => Domain Object; DTO = Domain Transfer Object; VM => View Model; V => View; Option 1: DL => DO => BL => DTO => PL => VM => V This option seems to be the Best Practice but also seems heavy to mantain. Option 2: DL => DO => BL => DTO => PL => V This option seems not very good practice but as DTO are almost identical to the VM, we can pass it directly to the View and it's less painfull to implement and mantain. Is this

How to call method in window (.xaml.cs) from viewmodel (.cs) without introducing new references in wpf

有些话、适合烂在心里 提交于 2019-11-29 17:01:19
问题 I'm looking for a simple way to call a method in my Main Window, but I want to call it from my View Model. Basically, I'm looking for some king of "this.parent" sort of thing to put in the View Model to reference the Main Window. Or, if you want to check out the reason I want to do this and tell me another way to go about my problem: I'm working with an app that constantly gets information fed to it. In the viewmodel, the information is processed. I want to make a notification every time a

Binding to viewmodel from inside a datatemplate

只谈情不闲聊 提交于 2019-11-29 16:21:38
问题 I have multiple videos displayed they are bound with a videocollection in Mainviewmodel. Everything works fine untill I try to bind the enter command to Mainviewmodel. I Don't know the syntax for this. As it stands the binding is set to Video and not Mainviewmodel. Errormessage: 'StartVideoCommand' property not found on 'object' ''Video' Xaml: <Window.Resources> <local:MainViewModel x:Key="MainViewModel"/> </Window.Resources> <Grid DataContext="{StaticResource MainViewModel}"> <ListBox