viewmodel

How to handle view model with multiple aggregate roots?

时光毁灭记忆、已成空白 提交于 2019-11-29 14:58:14
问题 At the moment, i got quite badly fashioned view model. Classes looks like this=> public class AccountActionsForm { public Reader Reader { get; set; } //something... } Problem is that Reader type comes from domain model (violation of SRP). Basically, i'm looking for design tips (i.e. is it a good idea to split view model to inputs/outputs?) how to make my view model friction-less and developer friendly (i.e. - mapping should work automatically using controller base class)? I'm aware of

How to use a Base ViewModel in Asp.net MVC 2

[亡魂溺海] 提交于 2019-11-29 14:35:56
问题 As I familiarize myself with Asp.Net MVC, I am using MVC 2, I have noticed the use of a BaseViewData class in the Kigg project which I am unsure how to implement. I want each of my ViewModels to have certain values available. Using an iterface comes to mind but I am wondering what the best practice is and how does Kigg do it? Kigg public abstract class BaseViewData { public string SiteTitle { get; set; } // ...other properties } public class UserListViewData : BaseViewData { public string

How can I open another view in WPF MVVM using click handlers and commands? (Is my solution reasonable?)

六眼飞鱼酱① 提交于 2019-11-29 12:30:50
I am writing a WPF application that has two windows. I have a MainWindowViewModel that holds two more view models: AllTagsViewModel and PlotViewModel . public AllTagsViewModel AllTagsViewModel { get; private set; } public PlotViewModel PlotViewModel { get; private set; } At the moment, I'm using this solution as a click handler in the main window: private void LaunchPlotWindow_OnClick(object sender, RoutedEventArgs e) { if (PlotWindow.GlobalInstanceCount == 0) { PlotWindow plotWindow = new PlotWindow(); PlotViewModel context = GetViewModel().PlotViewModel; plotWindow.DataContext = context;

DefaultModelBinder not binding nested model

你说的曾经没有我的故事 提交于 2019-11-29 12:28:10
问题 Looks like others have had this problem but I can't seem to find a solution. I have 2 Models: Person & BillingInfo: public class Person { public string Name { get; set;} public BillingInfo BillingInfo { get; set; } } public class BillingInfo { public string BillingName { get; set; } } And I'm trying to bind this straight into my Action using the DefaultModelBinder. public ActionResult DoStuff(Person model) { // do stuff } However, while the Person.Name property is set, the BillingInfo is

MVVM Main window control bind from child user control

眉间皱痕 提交于 2019-11-29 12:03:09
I’m very new to MVVM and getting my first POC done now. However, I have been hitting my head to get one issue resolved for 2 days. Thought of explaining to you guys may help and resolve the issue so quickly. Let me brief my issue now. I have WPF MVVM application with a main View bound to MainViewModel. I have Textblock here to bind some content from the viewmodel while loading the screen which is working awesome. I also have ChildUserControl bound to ChildViewModel. Now, I need to bind different content to the Textblock in the main window from user control up on some action which is taking

ASP.NET MVC view model best practices

泄露秘密 提交于 2019-11-29 09:07:44
问题 My ASP.NET MVC site connects to a WCF service to get data. The WCF service returns a data contract like this: [DataContract] public class Person { [DataMember] public string First { get; set; } [DataMember] public string Last { get; set; } } The view model in my MVC project looks like this: public class MyViewModel { public string SomeExtraField1 { get; set; } public string SomeExtraField2 { get; set; } public string SomeExtraField3 { get; set; } public Person Person { set; set; } } Should my

Binding property with parent ViewModel

£可爱£侵袭症+ 提交于 2019-11-29 08:03:26
Please refer to How can I tell my DataTemplate to bind to a property in the PARENT ViewModel? I have similar problem... But this solution didn't work for me. I have a MainViewModel which has an observable collection of another view model say View1/ViewModel1. This view has a tree control and I need context menu for the tree. My main view has a menu. Those main menu and context menu are connected. So how can I bind the context menu commands to the main viewmodel's properties? Basically, you need to use a RelativeSource binding. The standard way is to find an ancestor (or parent) of the control

Constructor injection of a View Model instance used as an Action method parameter

百般思念 提交于 2019-11-29 07:09:19
When a view model is created you can populate the options (e.g. used in a dropdown list) into a setter property of the view model. The problem is that when that view model is later passed as a parameter (by the framework!) into an action method, those property values has not become automagically repopulated, so if you need to redisplay the form because of validation errors, you need to repopulate those options again. One potential solution, which I am asking for specifically in this question, is how to make the MVC framework instantiate the view model with constructor injection, which would

File upload bound to the Viewmodel

无人久伴 提交于 2019-11-29 04:22:10
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 Upload(MyViewModel vm) The reason I want this viewmodel being posted is because I think its cleaner

Successful Model Editing without a bunch of hidden fields

匆匆过客 提交于 2019-11-29 02:56:34
问题 In Short : How do I successfully edit a DB entry without needing to include every single field for the Model inside of the Edit View? UPDATE So I have an item in the DB (an Article). I want to edit an article. The article I edit has many properties (Id, CreatedBy, DateCreated, Title, Body). Some of these properties never need to change (like Id, CreatedBy, DateCreated). So in my Edit View, I only want input fields for fields that can be changed (like Title, Body). When I implement an Edit