viewmodel

How can I share a ViewModel between parent/child Views (Silverlight 3.0)?

I have a parent View that is xaml-binded to a ViewModel (the viewmodel is declared in the xaml). This parent view can then display a child View (via NavigationService, aka navigation:Frame). The parent view never goes out of scope, but I want the new child View to share the parent's ViewModel. How can i do this? Because by declaring t...

Passing additional viewmodel data with EditorFor fails in one-to-many relatoinships

I have an editor template (Views/Shared/EditorTemplates/HORDER.ascx) which inherits System.Web.Mvc.ViewUserControl<CCOK2.Models.HORDER> My viewmodel has a one-to-many relationship which I use Html.EditorFor in order to render multiple HORDERS <%: Html.EditorFor(model => model.PEOPLE.HORDERS, new {fred="hello"})%> Eventually w...

Assert.AreEqual failed on two identical MVC ViewModel results?

I got this error on my unit test: Assert.AreEqual failed. Expected:<ShizoMe.Web.ViewModel.AccountViewModel>. Actual:<ShizoMe.Web.ViewModel.AccountViewModel>. This is the code for my test: [TestMethod] public void Register_Prevents_Duplicate_Users() { var controller = GetAccountController(); var model = new A...

The value for a object inside a viewmodel lost on redirect to action in asp.net mvc 2.0?

I have a view model - public class MyViewModel { public int id{get;set;}; Public SomeClass obj{get;set;}; } public class SomeClass { public int phone{get;set;}; public int zip{get;set;}; } So on my controller when I post back MyViewModel it has all the values for all the fields...but when I do return RedirectoAction("Som...

ASP.NET MVC 2: Data Annotation or Template: way to associate a DDL to its Model.data option list?

Summary: If you use ASP.NET MVC 2's templates to render a DropDownList, how would you access the list of options if they are stored in the top level View's Model.property? Also, is there some [DataAnnotation] way to associate this list? Links to examples would be very helpful. Background: In ASP.NET MVC 2, you can create a custom cl...

Populating properties on my Model with values from a SelectList when I post

I'm building an Asp.net MVC 2 application. I have an entity called Team that is mapped via public properties to two other entities called Gender and Grade. public class Team { public virtual int Id { get; private set; } public virtual string CoachesName { get; set; } public virtual string PrimaryPhone { get; set; } ...

ASP.NET MVC 2: Use [Data Annotations] to reference methods that could feed DDL lists?

A generally accepted way to pass all data to a view is to have a single data model with references to both your domain model and additional data for things like drop down lists (DDL). However, partial views (view templates too) receive only a portion of the main model, not able to access the root of the Model sent to the original view. ...

ASP.Net MVC maintain state of a dynamic list of checkboxes

I have a class called "PropertyFeature" which simply contains PropertyFeatureID and Description. It's a proper model created through LINQ to SQL mapped to an SQL Server database table. An example instance/row would be: PropertyFeatureID: 2 Description: "Swimming Pool" The number of rows (PropertyFeatures) can of course grow and shrink ...

Where should ViewModels be located?

/Controllers/ViewModels? /Views/ViewModels? Other? ...

dropdownlist and 2 listboxes: FormModel - asp.net mvc 2 question

There is a form: "dropdownlist", "available items listbox" and "selected items listbox", button: Add. "dropdownlist" is filled with values. OnDropdownChange "available items listbox" is populated with the values taken from db (ajax request). User, using Add button, moves elements from "available items listbox" to "selected items listbox...

Validation Attributes MVC 2 - checking one of two values

Hi guys/gals, Could someone help me with this issue. I'm trying to figure out how to check two values on a form, one of the two items has to be filled in. How do I do a check to ensure one or both of the items have been entered? I'm using viewmodels in ASP.NET MVC 2. Here's a little snip of code: The view: Email: <%=Html.TextBoxFor...

How to set EventArg for ICommand?

in VM, set ICommand like: private RelayCommand<EventArgs> _myCommand = null; public RelayCommand<EventArgs> MyCommand { get { if (_myCommand == null) { _myCommand = new RelayCommand<EventArgs>((e) => { //.... } ...

MVC2.NET pass object from viewmodel to view and acces it.

Hi, When working with Viewmodels from linq to sql I have an architectural problem. When you have an object from your db (let's say "person"), and you load it in your viewmodel. After this in your view, when you try to acces referenced classes (let's say a person has children object which is a different table in db, and a different data...

Binding pivot query to view in ASP.Net MVC

I'm sticking on how to best present some data that's being dynamically generated from two different tables. Given my query: var assets = assetRepo.Find(x => x.LoginId == User.Identity.Name); var accounts = repository.Find(x => x.AccStatus == "A" && x.LoginId == User.Identity.Name); var query = from asst in assets ...

"Type arguments cannot be inferred" error when using Html.TextboxFor with a ViewModel in an ASP.NET MVC 2 View

I'm writing an ASP.NET MVC 2 site where I have defined a custom ViewModel that I'm trying to use in a View. Unfortunately, I'm running into an error when using the ViewModel through a strongly-typed lambda expression. My Code Here's my ViewModel: [CompareProperties(ComparisonProperty1="EmailAddress", ComparisonProperty2="Confirm...

Transferring info in a ViewModel between Views and Controllers in an ASP.NET MVC 2 site without allowing modification of info

I'm building an ASP.NET MVC 2 site where I'm currently implementing an OpenID sign-up form. Unfortunately, I'm foreseeing a possible security bug/vulnerability inside my architecture. Here's how I want OpenID login to work: User requests /Account/Login, Controller sends back OpenIDLogin View. User enters their OpenID into the View, th...

ASP.NET MVC Trouble getting data and related data to the view. (View Model Pattern?)

My site has Users. My site has Items. Users can leave a Review of an Item. Users can leave a Rating of an Item. When users rate an Item, they rate it in different categories: a rating for build quality, a rating for usefulness, a rating for aesthetic appeal. So, in my database, my Reviews table would have one entry and my Ratings tab...

WP7 SL - How can I use two different View Models in a View. One VM: Display, other for User input and acting on it

I am using ViewModelLocator pattern. I have the following situation: Page1<->VM1 => Navigate => Page2<->VM1 => Navigate => Page3<->VM3 => Page 4<->VM4 => Page 5<->VM5 I will show Page2 using VM1 but the controls that will take input w...

Basic View Model class reference question. (ASP.net MVC)

Newbie-ish questions ahead: Where should I put my View Model declarations? I created a file called "ViewModels.cs" in my Models folder. I created a few View Model classes, including one called RatingViewModel: using System; using System.Collections.Generic;var using System.Linq; using System.Web; namespace Web.Model { public class Vi...

View strongly-typed with ViewModel doesn't generate fields automatically

When I create a view and bind it directly to one class which has the properties I want to show on the view, the fields (textboxes, etc.) for it are created automatically. But when I create a ViewModel to encapsulate more than one object with data, this doesn't happen. Is there any way to get that working for a specific object which is in...