viewmodel

Proper way to validate model in ASP.NET MVC 2 and ViewModel apporach

I am writing an ASP.NET MVC 2 application using NHibernate and repository pattern. I have an assembly that contains my model (business entities), moreover in my web project I want to use flattened objects (possibly with additional properties/logic) as ViewModels. These VMs contain UI-specific metadata (eg. DisplayAttribute used by Html.L...

Which layer should construct a View Model?

Hi Guys, I'm using the S#arp architecture, and I can't remember where I read it, but they say they ViewModels should be stored at the service layer, and your views should submit the viewmodel to the service for processing. My question then is this. Which layer should construct the ViewModel? Should it be at the service layer, and the ...

Customize WPF databinding: How to add custom logic?

Hi, i have a question regarding some complex data-binding. I want to be able to update a grid (which has the property "IsItemsHost" set to true) dynamically whenever a data-binding occurs. Actually i am using a CustomControl which is an ItemsControl and this has the Grid in its ControlTemplate. To be more specific, i bind the grid to ...

MVVM: Delete a CustomerViewModel, but how to get the Customer model inside it?

Hello, I have a list of CustomerViewModels in a ComboBox. The selected CustomerViewModel I want to delete and also the Customer wrapped inside it to remove it from the repository. But how can I access the Customer model inside the CustomerViewModel? ...

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

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 pub...

Keeping Linq to SQL alive when using ViewModels (ASP.NET MVC)

I have recently started using custom ViewModels (For example, CustomerViewModel) public class CustomerViewModel { public IList<Customer> Customers{ get; set; } public int ProductId{ get; set; } public CustomerViewModel(IList<Customer> customers, int productId) { this.Customers= customers; this.Product...

WPF/MVVM:Set multiple datacontext to ONE usercontrol

Hello, I have a UserControl with 5 small UserControl which are parts of the first UserControl. The first UserControl is datatemplated by a MainViewModel type. The other 5 small UserControls have also set the DataContext to this MainViewModel type. Now I want additionally that those 5 UserControls get a 2nd DataContext to access other...

What kind of data belongs in a view model?

The name "view model" suggests that it models the data for the view. That much is obvious. What else can or should go in the view model? As an example, a view might display a list of items in a shopping cart, fields for customer's credit card info, and fields for customer's billing information. The view model might contain properties f...

return list from view to controller via viewmodel

I have a controller that takes in a viewmodel and submitbutton public ActionResult AddLocation(AddLocationViewModel viewModel, string submitButton) My view is bound to the viewmodel. The viewmodel contains a list objects used to create an html table with checkboxes. Is there a way to access the selected "rows" through the viewmodel in ...

MVVM pattern and nested view models - communication and lookup lists

I am using Prism for a new application that I am creating. There are several lookup lists that will be used in several places in the application. Therefore it makes sense to define it once and use that everywhere I need that functionality. My current solution is to use typed data templates to render the controls inside a content control....

MVVM - several workspaces in a workspace seems not to make sense...

So how do you display complex aggregated ViewModels whose Models have relations to each other? NO wpf disciple ever spoke about that, guess why its not possible... Do you think thats true? Don`t understand me? Look: A CustomerViewModel has many OrderViewModel and those many ProductViewModel. You have 3 Workspaces to enter the new d...

Where and how to validate and map ViewModel?

Hi, I am trying to learn Domain Driven Design and recently read that lots of people advocate creating a ViewModels for your views that store all the values you want to display in a given view. My question is how should I do the form validation? should I create separate validation classes for each view, or group them together? I'm also c...

How to access view model data in jquery?

In my html, I use Model.Subcontract.company How can I reference that data in my jQuery? ...

What is good practice in .NET system architecture design concerning multiple models and aggregates

I'm designing a larger enterprise architecture and I'm in a doubt about how to separate the models and design those. There are several points I'd like suggestions for: - models to define - way to define models Currently my idea is to define: Core (domain) model Repositories to get data to that domain model from a database or other sto...

WPF InotifyPropertyChanged and view models

So I think I'm doing something pretty basic. I know why this doesn't work, but it seems like there should be a straight foward way to make it work. code: private string fooImageRoot; // .... public BitmapImage FooImage { get { URI imageURI = new URI(Path.Combine(fooImageRoot, CurrentFooTypes.FooObject.FooImageName)); retu...

MVVM:How am I supposed to convert a ViewModel into a Model ?

Hello, everyone speaks about wrapping a model by a viewmodel. fine so far. But when I want persist my Model, how do I convert a ViewModel into a Model ? Reading all properties from the ViewModel into a new Model object seems very cumbersome. Any better method? ...

Should I map a domain object to a view model using an optional constructor?

I'd like to be able to map a domain model to a view model by newing up a view model and passing in the contributing domain model as a parameter (like the code below). My motivation is to keep from re-using mapping code AND to provide a simple way to map (not using automapper yet). A friend says the view model should not know anything abo...

How should be my DTO object for ASP.Net MVC View ?

Hi all, i'd like to know, I have a application in asp.net mvc and nhibernate. I've read about that in the Views on asp.net mvc, shouldn't know about the Domain, and it need use a DTO object. So, I'm trying to do this, I found the AutoMapper component and I don't know the correct way to do my DTOS, for some domain objects. I have a domain...

MVVM/WPF: Using a ObservableCollection<T> as a list in a domain model, is that good/bad ?

I have aggregated models like Customer:Order:Product. As my View is bound to the BillingViewModel which has a Property Customers of type ObservableCollection and ONE customer in this collection has a "list" of orders named ObservableCollection and ONE order in this collection has a "list" of products named ObservableCollection Well ...

WPF/MVVM: How can I use several CollectionView`s for aggregated entities ?

Hello, I have a Customer with Orders and those have products. Everything aggregated with collections of type ObservableCollection. All 3 collections are bound to a datagrid/combobox. I can only make the root collection (ObservableCollection Customers{ get;set;} ) passing to a CollectionView so I can move the current customer within t...