viewmodel

ViewModel Best Practices

From this question, it looks like it makes sense to have a controller create a ViewModel that more accurately reflects the model that the view is trying to display, but I'm curious about some of the conventions (I'm new to the MVC pattern, if it wasn't already obvious). Basically, I had the following questions: I normally like to have...

WPF - Best way of responding to changes in a ViewModel at Page/Window level

I'm developing an XBAP and i have a simple requirement. The DataContext of the whole main page is set to an instance of my UserViewModel. The UserViewModel has a DependencyProperty called AuthenticationState which is an enum with values like 'Authenticated','NotAutheticated' and 'AuthenticationFailed'. Now, i need to respond to an...

ASP.net MVC - ViewModel object and Session variables

Say I have the following situation: A paginated View displays a list of contacts with the following route: Contacts/Index/Page/2. The View gets its paginated data ViewModel object. The View also gets its filter properties from the ViewModel, like the Contact Category. I would like to store the page number and the filter properties ...

Best way to CustomViewData?

What's the most practical way to add custom properties to a side wide ViewDataDictionary? Let's assume a simple case: public ActionResult Index() { // ViewData["Title"] = "Home"; ViewData.Title = "Home"; return View(); } The first thing that comes to mind is a custom class and using "new" in a application base controller: publ...

MVC Custom ViewModel and auto binding

I have a custom ViewModel defined as : public class SampleFormViewModel { public SampleFormViewModel(SelectList companies, Widget widget) { Companies = companies; Widget = widget; } public SelectList Companies { get; private set; } public Widget Widget { get; private set; } } In my Edit POST handle...

How to create a strongly typed master page using a base controller in ASP.NET MVC

Following the NerdDinners example, I am interested in creating a strongly typed Master Page. In order to achieve this, I use a base controller which retrieves the data for the master page. All other controllers inherit this class. Similarly, I have ViewModels for the master page and any other views. The view ViewModel classes inherit fro...

ASP.NET MVC - different models for master page and view page

I have a strongly typed master page, but I want to use a different type for some of it's child pages. For example, on the master page... <%@ Master ... Inherits="System.Web.Mvc.ViewMasterPage<MyWeb.Models.Client>" %> Client is already a composite object, so on some of the child pages I can keep to the same model and just reference me...

How does DataAnnotationsModelBinder work with custom ViewModels?

Hi, I'm trying to use the DataAnnotationsModelBinder in order to use Data Annotations for server-side validation in ASP.NET MVC. Everything works fine as long as my ViewModel is just a simple class with immediate properties such as public class Foo { public int Bar {get;set;} } However, the DataAnnotationsModelBinder causes a N...

What are the biggest pain points with the ViewModel pattern?

Glenn Block and I have been working together on the ViewModel pattern. We’ve been trying to identify the biggest pain points associated with the pattern, with the goal of adding framework support to alleviate the pain. Tonight, Glenn posted, “View Model” – the movie, cast your vote. We want to hear from you. Please post here (and vot...

MVVM Pattern, ViewModel DataContext question

I need to figure out how to communicate between ViewModels. I'm new to MVVM so please be kind. Here's a dumbed down example class definitions(assume that I have hooked the Child.PropertyChanged event in the ParentViewModel): public class ParentViewModel : ViewModelBase { public ChildViewModel Child { get; set; } } public class Ch...

How to present a Collection of (View)Models in a ViewModel

Hi. I have a question regarding the MVVM design for C#/WPF. I've had a look at several demo applications, but they didn't really handle my problem. My application consists of objects that contain other objects. Much like in a parent - children relationship. My question now is: does the children attribute have to be a ViewModel and ...

MVC custom viewmodel problems

I'm a bit of an MVC newbie, so you'll have to forgive what I imagine is an elementary question. I created a custom viewmodel in order to have a multiselect list in my form: public class CustomerFormViewModel { public Customer Customer { get; private set; } public MultiSelectList CustomerType { get; private set; } public Cu...

Viewmodel security in asp.net mvc

Is there a difference in terms of security between these two models to be given to View? Ie. in the second example can a webuser/hacker access the methods in any way? public class ObjectViewModel { public PropertyA {get;set;} public PropertyB {get;set;} public PropertyC {get;set;} } public class ObjectViewModel2 { ...

How do you keep view logic out of the model and business logic out of the view-model in MVVM?

I can't quite figure out how to get the view model to be notified of changes in the model without adding a bunch of UI specific stuff like INotifyProperyChanged and INotifyCollectionChanged in my model or create tons of different events and do a bunch of things that feel like they're UI specific and should stay out of the model. Otherwi...

IEnumerable and string array - find matching values

Background: I have an ASP.NET MVC view page with a MultiSelectList in the View Model. I want to populate a label with the list of SelectedValues from that MultiSelectList object. The list is stored within the MultiSelectList with a type of IDName: public class IDName { public int ID {get; set;} public string Name {get; set;} } ...

MVVM Tabcontrol change tab

I am developing an mvvm app with wpf. A requirement just got added on to block the user from changing tabs if a textbox has text. What is the best way to do this completely in the viewmodel? I don't know how to block a tabitem because there is no dependencyobject command in the tabcontrol to tie into, do i need to roll my own tabcontro...

MVVM ICommand alternative

I have begun creating a wpf mvvm app. It seems a vital ingredient to the ViewModel is a bunch of ICommands to have a loosely coupled way of allowing the view to interact with the viewmodel. My question is this, why can't I bind directly to a method? I have used Josh Smith's RelayCommand implementation of ICommand that allows you to in...

Best practice for parent/child-viewmodel-relationships in MVVM using Onyx?

Hy guys! I am currently working on a little WPF project using MVVM via the Onyx framework. My currentview architecture is like this: <DockPanel> <Menu DockPanel.Dock="Top" Background="#cecece"> <!-- Menu --> </Menu> <Grid> <views:TranslationView x:Name="translationView" /> </Grid> </DockPanel> ...

Proper submission of forms with autogenerated controls

Based on: http://stackoverflow.com/questions/658458/mvc-html-checkbox-and-form-submit-issue Let's consider following example. View: <% using(Html.BeginForm("Retrieve", "Home")) %> <% { %> <%foreach (var app in newApps) { %> <tr> <td><%=Html.CheckBox(""+app.ApplicationId )%></td> </tr> ...

In MVVM are DataTemplates considered Views as UserControls are Views?

In MVVM, every View has a ViewModel. A View I understand to be a Window, Page or UserControl to which you can attach a ViewModel from which the view gets its data. But a DataTemplate can also render a ViewModel's data. So I understand a DataTemplate to be another "View", but there seem to be differences, e.g. Windows, Pages, and UserCo...