viewmodel

What is the correct way to initialize a model and view in WPF CAL MVVM.

I have come accross two ways of initializing Views and ViewModels in WPF CAL MVVM. 1 - Seems to be more popular. Requires you to resolve the ViewModel to automatically resolve the View. The ViewModel contains information about the View. public interface IView { void SetModel(IViewModel model); } public interfac...

AutoMapper - How to pass parameters into a Custom Resolver using ConstructedBy method?

In my ASP.NET MVC 2 (RC) project - I'm using AutoMapper to map between a Linq to Sql class (Media) and a view model (MediaVM). The view model has a SelectList property for a drop down in the view. I have a custom value resolver to populate the SelectList property items from the db, but am wondering if there's a way to pass a couple value...

Mapping Validation Attributes From Domain Entity to DTO

Hi, I have a standard Domain Layer entity: public class Product { public int Id { get; set; } public string Name { get; set; } public decimal Price { get; set;} } which has some kind of validation attributes applied: public class Product { public int Id { get; set; } [NotEmpty, NotShorterThan10Characters, NotL...

How do I handle a filtered and unfiltered list in the same asp.net mvc view?

Hi everyone, I need a way to display whether a user has subscribed to a service or not and to display it into a table in a view. So far I am able to show if that a user has subscribed to a service but am not able to show when they have not subscribed. I created a viewmodel like this: public class MyServicesController : Controller...

asp.net mvc multiselect remember state after postback

Hi, I am using the DataAnnotations for error checking on my asp.net mvc app, I am also using strongly typed ViewModels too. My error checking is working fine and is posting back to my view with error messages if a field is blank. However i have a MultiSelect / Listbox on my form which i need to remember it's state after an error. At t...

WPF Conditional Validation

I'm having problems validating an email address in my View Model. Property I'm checking is - [ValidatorComposition(CompositionType.And)] [SOME Operator("EnabledField")] [RegexValidator("\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*", Ruleset = "RuleSetA", MessageTemplate = "Invalid Email Address")] public ...

Combine ViewModel (WPF/Silverlight) and strongly-typed ViewData (ASp.NET MVC)?

Note: I will use the term "ViewModel" for both the ViewModel in WPF/Silverlight and the strongly-typed ViewData in ASP.Net MVC in the following text. I would like to create both ASP.Net MVC and WPF/Silverlight clients for the same project (in other words, against the same DataModel), should I create a common ViewModel project or a separ...

ASP.NET MVC terminology is tripping me up - why 'ViewModel'?

I'm an ASP.NET MVC newbie, but have used many Model-View-Controller frameworks previously. I recently came across the convention of gathering up the pieces of data that your particular view needs (indeed, it's assigned to the ViewData) into a new class called (NameOfView)ViewModel. Gathering up this data so that it's associated with th...

Hydrating ViewModels in ASP.NET MVC

I have a page that is made up of many user controls. The view model for this page is rather complex. public class ComplexViewModel { public ObjectA ObjectAProperty { get; set; } public List<Things> ListOfThings { get; set; } public List<ThingCategories> ListOfThingCategories { get; set; } public List<ThingTypes> ListOfT...

Unable to write to NSTextField from Model Controller object

After always running monolithic blocks of code from within my AppController object, I've just learned how to modularize my code using separate model controller objects (so much neater and less confusing to work with :-)) My simple test app has a main AppController and two model objects (Model1 and Model2). I can successfully pass data f...

How to keep collections of viewmodels and models in sync

Hi, I'm using the wpf toolkit datagrid to display an observable collection of AccountViewModels. The thing is when I delete an account from the grid, I want it removed from the ObservableCollection - to give the user visual feedback, but i want the underlying list of Account models to remain the same, just with an 'IsDeleted' flag set ...

Does a ViewModel have its own logic ?

When assigning ViewModel fields, should the domain objects be passed directly to the ViewModel objects which will then determine how to present the data, or should another class like a service be assigning data from the Model to the ViewModel? also: EDIT:is there any sense in dividing a viewmodel into receiver and presenter? (instead ...

ASP.NET MVC ViewModel and DropDownList

I have 2 properties in my ViewModel class ViewModel1 { Dictonary<int, string> PossibleValues {get;set;}//key/value int SelectedKey {get;set} } I want to edit this using a Html.DropDownListFor I want to get MVC to auto serialize the data into/from the ViewModel so I can the following public ActionResult Edit(ViewModel1 model)...

Does ASP.Net MVC 2 validation need some more thought in terms of patterns and use?

Hey guys Here is the lay of the land. Like most people I have my domain object and I have my view models. I love the idea of using view models, as it allows for models to be created specifically for a given view context, without needing to alter my business objects. The problem I have is with type level validation defined on my domain...

Different versions of the same entity type (any ORM) for different roles/authorization levels.

Consider, for example: public interface IStaff { FullName name { get; set; } EMailAddress email_address { get; set; } SocialInsuranceId ssn { get; set; } PositiveInt age { get; set; } Address home_address { get; set; } } For some users, the viewmodel will only require name and email_address. Others may have a view...

Model-binding an object from the repository by several keys

Suppose the following route: {region}/{storehouse}/{controller}/{action} These two parameters region and storehouse altogether identify a single entity - a Storehouse. Thus, a bunch of controllers are being called in the context of some storehouse. And I'd like to write actions like this: public ActionResult SomeAction(Storehouse sto...

ViewModel approach interferes with ModelBinding in MVC 2 when using the new "For" HTML helpers

I am using .net MVC 2.0 and have set up an edit view that receives a custom ViewModel object. The ViewModel is a class with two properties: // Properties public Portfolio Portfolio { get; private set; } public SelectList slSectors { get; private set; } In my view there is a form with the purpose of updating the Portfolio Object. The...

How to map View Model back to Domain Model in a POST action?

Every article found in the Internet on using ViewModels and utilizing Automapper gives the guidelines of the "Controller -> View" direction mapping. You take a domain model along with all Select Lists into one specialized ViewModel and pass it to the view. That's clear and fine. The view has a form, and eventually we are in the POST act...

ASP.MVC 1.0 complex ViewModel not populating on Action

Hi, I'm 3 days into learning MVC for a new project and i've managed to stumble my way over the multitude of issues I've come across - mainly about something as simple as moving data to a view and back into the controller in a type-safe (and manageable) manner. This is the latest. I've seen this reported before but nothing advised has s...

ASP.net MVC demo projects that use View Models

Hey guys Just wondering if there are any good projects out there that use View Models. I am trying to get my implementation nailed down for how we are going to use VM's and there seems to be a few cross roads that I am coming up to and am wanting to see how other people handle these. Big bonus if the project uses ASP.net MVC 2.0. Che...