viewmodel

How should I structure my ViewModel for this hierarchical data I need to display in ASP.NET MVC?

I have a view that will look like this: I'm trying to figure out how I should represent my ViewModel for this view. Each "Agency" can have multiple "Business Units" and each "Business Unit" can have several "Clients". In the database I easily represent this with a mapping table and foreign keys for the Agency, BusinessUnit and Clien...

Need help with LINQ query and ASP.NET MVC?

My repository returns a list of Accounts. Each account has a date and a MoneySpent decimal amount. So, I have my list of Accounts and in my controller I'm trying to process this list a little. I want to have an object which contains the string name of all the months in my Account list and a Sum of all money spent for that month. Here...

MVVM - Controls versus Views

I've been doing a prototype in WPF without using MVVM. It's got to such a size now that I'm refactoring it to use MVVM. When I started the project, I jumped straight in and created UserControls for lots of things. I'm now breaking things in Views and ViewModels. But, I'm ending up with Views that contain UserControls; the UserControl...

Silverlight 3 Beta, NavigationService in the ViewModel

Hi, im developing a silverlight 3 beta navigation application, so i've gone with a slight variation of the MVVM pattern :) (all-in-one viewmodel), using prism, and stuff. Question: How do i navigate to a different "NavigationPage" in the viewmodel Now to cut a long story short, the viewmodel is declared as a page resource. <navigation...

Calling ViewModel Methods

I'm pretty new to WPF and using the MVVM design pattern. To help learn this, I'm developing a simple dice-rolling application. Right now, I have a Dice class and a DiceViewModel class. I also have a MainWindowViewModel class that contains an observable collection of DiceViewModels. When a user clicks the "Roll" button, it launches a ...

Updating items inside ListBox

I have a ListBox bound to an observable collection of DiceViewModel. Whenever I click a button to add a new item, the ListBox displays the new item like I expect. Everything so far is working well. <ListBox ItemsSource="{Binding Path=AllDice}" DisplayMemberPath="Value"/> However, I have another button to roll all existing dice. ...

User Interface Interaction with the MVVM

I did some googling and didn't find an answer to this puzzle. Provided you have the following: MySuperView MySuperViewModel MySuperView has two textboxes both bound to string properties on the ViewModel and your using a DelegateCommand to bind your 'Save' button to the ViewModel using syntax such as: ViewModel: this.SaveOrderComm...

Silverlight DataGrid.Celltemplate Binding to ViewModel

Hi. I am in the process of implimenting the MVVC pattern and am having trouble binding a property in the viewmodel from within a DataTemplate within a datagrid. If I have a textblock outside the DataTemplate in the column it works fine (since I am directly referencing the datacontext of the UserConrol, i.e. the VM) however from within t...

Unit testing controller actions with complex viewModels

Hi, I'm just getting going with ASP.NET MVC and I'm also new to unit testing :) So far, so good. I have a controller action that sets up an index view using a viewmodel. Testing the controller action is straight-forward as I can pass a fake service class in the controller's constructor, but my viewmodel is quite complex and fetches i...

Validation on ViewModels in ASP.NET MVC

Most of the tips on how to implement validation in ASP.NET MVC seem to center around the Model (either building service layers between model and controller or decorating properties of the model with validation attributes). In my application I use ViewModels for all communication between the controllers and the views. I have a ViewMode...

Can jQuery do a POST of a ViewModel to a Controller in ASP.NET MVC?

I have my Html Textboxes created so that they will be bound to a custom view model when posting back to the server. <%= Html.TextBox("CustomerFormViewModel.Email")%> This works great if it's a traditional POST. I can then receive it on the Controller side with something like this: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Add...

AutoMapper flattens Domain Models but does it do the opposite? If not, what does?

I've been reading up on AutoMapper because of a response to one of my earlier questions here. It says that AutoMapper flattens complex domain models, but I need something that does the opposite. I need to wire up my view models (flattened domain models) to the complex domain models so that I can quickly transform a view model into a doma...

Validation not working on plain objects in ASP.NET MVC

When I post a 'Model' object (as generated by LinqToSQL) to a controller, I can query 'ModelState.IsValid', and if there are validation attributes on any of the properties and the value doesn't validate, it will be set to 'false'. However, ModelState.IsValid seems to always return 'true' if I'm posting a custom object of my own class, e...

WPF MVVM Threadsafe way to get List<Object> from ViewModel

I am trying to access a List on a view model from a background worker, but am getting errors because I am going cross thread... This is the problem method on the viewmodel: (I am getting the exception the first line in the function (SMMainWindow window ...)) public static MainWindowViewModel GetMainWindowViewModel() { SMMai...

Grids with ViewModels - WPF

Sorry if this has already been asked, but I just want to make sure that I'm doing this right. If I have a domian object that has say 10 properties on it. I have a grid on my main form that I want to show the pretty much all the the properties from the model. I created a viewmodel to wrap the domain object to show in the gridview but t...

ASP.NET MVC - Job of Controllers

Hello, I think I'm beginning to be confused with the job of a controller in MVC. I have a service that exposes five functions: list packages in queue get package delete package accept package deny package My ASP.NET MVC controller depends on this service, and can generally execute a service call on an Action. I'm happy so far. Th...

ASP.NET MVC Model/ViewModel Validation

I have model classes in Linq-to-Sql with partial classes marked with data annotation attributes and a reference to xVal. When I bind a view directly to a model everything works great, both the JS generated by xVal and server side double check. Many of my views don't take input to one specific model, so I am setting up view model cl...

Two model view designs and communication between models

I have a dialog box with two disctinct parts. Each part uses a model view design. But when a model is updated, the second one has to be updated too. I’m wondering if it exists any best pratice or design pattern for communicating (update notification) between two models. That's not realy possible to have two views and only one model. Tha...

Custom ViewModel Class - Not all fields are marked invalid unless a prefix is specified

I have a custom viewmodel inside which I have two fields and one linq2sql entity .. all fields have Validation Attributes attached. Even if all fields are invalid only the fields in the linq2sql class are visually indicated for error and fields in the viewmodel are displayed normally. But the error messages are displayed for all invalid ...

using ViewModels for POST actions in MVC elegantly

Currently I'm passing my domain objects to my views, and binding directly to them from POSTs. Everyone says this is bad, so I'm attempting to add in the ViewModel concept. However, I can't find a way to do this very elegantly, and I'd like to know what other people's solutions are to not ending up with a very messy controller action. t...