viewmodel

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

喜夏-厌秋 提交于 2019-11-28 20:55:39
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 the functions provided by the View/Controller interaction strikes me as a helper struct, or even closure mechanism (in the 'encapsulates a collection of variables' sense). So why is it called 'ViewModel', given that it's neither a View or Model? Does anyone else

EditorFor collection of items in my model

你离开我真会死。 提交于 2019-11-28 20:14:36
问题 My ViewModel has a property that is a collection of another of my model entities, in this case CategoryTags (and each tag has a Tag and an ID). 1) Am I correct in understanding that Html.EditorFor() doesn't have an UI it can create for an ICollection? 2) Assuming #1, I've decided to make an EditorTemplate that is a textbox where my user can key in comma-separated tag names and jquery will autocomplete. Will I have to pass back the list of tag names (or their respective IDs) and then parse

WPF MVVM communication between View Model

一个人想着一个人 提交于 2019-11-28 19:47:35
I am working on WPF MVVM application wherein I have 2 views View1 and View2 with their respective ViewModels. Now, I want on click of a button in View1 would close View1 and open View2 using ViewModel1. Also, I want to pass some data say a instance of person class to ViewModel2 when opening from ViewModel1 which would be used to display information in View2. What is the best and possibly the simplest way to achieve this inside ViewModels only, I would want to avoid writing code for navigation in code behind. How about using the Mediator pattern (for example see technical-recipes.com or John

ASP.NET MVC 2 - Html.DropDownListFor confusion with ViewModel

亡梦爱人 提交于 2019-11-28 18:42:07
问题 I'm getting totally lost and confused on how to use the new strongly typed Html.DropDownListFor helper on ASP.NET MVC 2.0 R2 In the View I'm writting: <%= Html.DropDownListFor(m => m.ParentCategory, new SelectList(Model.Categories, "CategoryId", "Name", Model.ParentCategory), "[ None ]")%> <%= Html.ValidationMessageFor(m => m.ParentCategory)%> and my Model object is thus: public class CategoryForm : FormModelBase { public CategoryForm() { Categories = new List<Category>(); Categories.Add(new

Mapping Validation Attributes From Domain Entity to DTO

三世轮回 提交于 2019-11-28 17:01:13
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, NotLongerThan100Characters] public string Name { get; set; } [NotLessThan0] public decimal Price { get; set;} } As you can see, I have made up these attributes completely. Which validation framework (NHibernate Validator, DataAnnotations, ValidationApplicationBlock, Castle Validator, etc) in use

WPF: how to signal an event from ViewModel to View without code in codebehind? [duplicate]

这一生的挚爱 提交于 2019-11-28 16:59:37
This question already has an answer here: How can I Have a WPF EventTrigger on a View trigger when the underlying Viewmodel dictates it should? 4 answers I have quite simple (I hope :)) problem: In MVVM, View usually listens on changes of ViewModel's properties. However, I would sometimes like to listen on event, so that, for example, View could start animation, or close window, when VM signals. Doing it via bool property with NotifyPropertyChanged (and starting animation only when it changes from false to true) is possible, but it feels like a hack, I'd much prefer to expose event, as it is

Domain vs DTO vs ViewModel - How and When to use them?

允我心安 提交于 2019-11-28 16:19:07
问题 In a Multi-layer project with Domain layer (DL)/Business (Service) Layer (BL)/Presentation Layer (PL), what is the best approach to deliver Entities to the Presentation Layer? DO => Domain Object; DTO = Domain Transfer Object; VM => View Model; V => View; Option 1: DL => DO => BL => DTO => PL => VM => V This option seems to be the Best Practice but also seems heavy to mantain. Option 2: DL => DO => BL => DTO => PL => V This option seems not very good practice but as DTO are almost identical

MVVM and collections of VMs

∥☆過路亽.° 提交于 2019-11-28 16:11:52
A common senario: A model with a collection of item models. E.g a House with a collection of People. How to structure this correctly for MVVM - particulary with regard to updating the Model and ViewModel collections with additions and deletes? Model House contains a collection of model People (normally a List<People> ). View model HouseVM contains the House object that it wraps and an ObservableCollection of view model PeopleVM ( ObservableCollection<PeopleVM> ). Note that we end up here with the HouseVM holding two collections (that require syncing): 1. HouseVM.House.List<People> 2. HouseVM

Return a List<E> from a view in view model

匆匆过客 提交于 2019-11-28 14:48:20
This is my situation: I have this view model: public class ViewModel { public DateTime someDate { get; set; } public String someString { get; set; } public List<E> someList { get; set; } } What I have to do is in the view set the date, write some text and then select from a list of E any number of E. The ViewModel returned in the action must have the date, the text and contain the list of selected items. What I need to know is how to handle said list. How can I add each selected item to the models' List. I was thinking on adding a property public bool selected to E and then send all items and

Silverlight DataGrid.Celltemplate Binding to ViewModel

家住魔仙堡 提交于 2019-11-28 13:46:25
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 the DataTemplate it wont return the plain text property. It will however return a property from the iterated IEnumerable item. <UserControl xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" x:Class="Timesheet.Silverlight.Modules