viewmodel

When do I use View Models, Partials, Templates and handle child bindings with MVC 3

你离开我真会死。 提交于 2019-11-26 11:07:37
问题 new to mvc3, i have a few questions, would appreciate if someone could answer/provide links: When should I use View Models? Is it not recommended to use the domain? I find that my view models are copies of my domain objects, and don\'t see the value... When should I use Partials? Is it only if the partial view will be reused? When should I use Display Templates and Editor Templates? Can I use these without a view model? How do I create an edit screen where the parent and list of child objects

ItemsControl with multiple DataTemplates for a viewmodel

送分小仙女□ 提交于 2019-11-26 10:58:37
问题 is it possible to bind an itemscontrol with canvas as template to multiple DataTemplates? I have 2 collections and depending on the type I would like to display a different control on my canvas. I am not sure but I could think about a Viewmodel which has 2 ObservableCollections. For example if I would have \"Shapes\" and \"connections\" and I would like to display them both on the canvas? In case of a diagraming scenario... I would like to do this in the mvvm manner and I am not sure if the

How to bind WPF button to a command in ViewModelBase?

爱⌒轻易说出口 提交于 2019-11-26 07:56:20
I have a view AttributeView that contains all sorts of attributes. There's also a button that when pressed, it should set the default values to the attributes. I also have a ViewModelBase class that is a base class for all ViewModels I have. The problem is I can't seem to get the button bound to the command with WPF. I've tried this, but it just doesn't do anything: <Button Command="{Binding DataInitialization}" Content="{x:Static localProperties:Resources.BtnReinitializeData}"></Button> The command is defined (in the ViewModelBase ) like this: public CommandBase DataInitialization { get;

WPF - Should a user control have its own ViewModel?

久未见 提交于 2019-11-26 07:30:36
问题 I have a window made up of several user controls and was wondering whether each user control have its own ViewModel or should the window as a whole have only one ViewModel? 回答1: This is not a yes or no question. It depends on whether having extra view models affords you better maintainability or testability. There's no point adding view models if it doesn't gain you anything. You'll need to gauge whether the overhead is worth it to your particular use case. 回答2: Absolutely, positively NO Your

ASP.NET MVC ViewModel Pattern

爷,独闯天下 提交于 2019-11-26 06:37:27
问题 EDIT: I made something much better to fill and read data from a view using ViewModels , called it ValueInjecter . http://valueinjecter.codeplex.com/ it is used by http://prodinner.codeplex.com - an ASP.net MVC sample application you can see the best way of using ViewModels in prodinner using the ViewModel to store the mapping logic was not such a good idea because there was repetition and SRP violation, but now with the ValueInjecter I have clean ViewModels and dry mapping code That\'s the

ASP.NET MVC - How exactly to use View Models

浪子不回头ぞ 提交于 2019-11-26 04:20:10
问题 Let\'s say I have a page that allows the editing of a user\'s details, so I have a ViewModel like this: public class UserViewModel { public string Username { get; set; } public string Password { get; set; } public int ManagerId { get; set; } public string Category { get; set; } } So on my EditUser action I can have this passed back by the model binder and then I can map that to the Domain Model: public ActionResult EditUser(UserViewModel user) { ... However, the page that displays the form

ASP.NET MVC Model vs ViewModel

孤者浪人 提交于 2019-11-26 04:08:56
问题 OK, I have been hearing discussion about \"ViewModels\" in regards to MS\'s ASP.NET MVC. Now, that is intended to be a specific kind of Model, correct? Not a specific kind of View. To my understanding, it\'s a kind of Model that has a specific purpose of interacting with the View? Or something like that? Some clarification would be appreciated. 回答1: Essentially Model and View Model are both simple classes with attributes. The main objective of these classes are to describe (to "Model") an

Ignore mapping one property with Automapper

孤街醉人 提交于 2019-11-26 03:48:51
问题 I\'m using Automapper and I have the following scenario: Class OrderModel has a property called \'ProductName\' that isn\'t in the database. So when I try to do the mapping with: Mapper.CreateMap<OrderModel, Orders>(); It generates an exception : \"The following 1 properties on Project.ViewModels.OrderModel are not mapped: \'ProductName\' I\'ve read at AutoMapper\'s Wiki for Projections the opposite case (the extra attribute is on the destination, not in the source which is actually my case )

How to bind WPF button to a command in ViewModelBase?

心不动则不痛 提交于 2019-11-26 03:25:09
问题 I have a view AttributeView that contains all sorts of attributes. There\'s also a button that when pressed, it should set the default values to the attributes. I also have a ViewModelBase class that is a base class for all ViewModels I have. The problem is I can\'t seem to get the button bound to the command with WPF. I\'ve tried this, but it just doesn\'t do anything: <Button Command=\"{Binding DataInitialization}\" Content=\"{x:Static localProperties:Resources.BtnReinitializeData}\"><

Two models in one view in ASP MVC 3

痴心易碎 提交于 2019-11-26 03:15:57
问题 I have 2 models: public class Person { public int PersonID { get; set; } public string PersonName { get; set; } } public class Order { public int OrderID { get; set; } public int TotalSum { get; set; } } I want edit objects of BOTH classes in SINGLE view, so I need something like: @model _try2models.Models.Person @model _try2models.Models.Order @using(Html.BeginForm()) { @Html.EditorFor(x => x.PersonID) @Html.EditorFor(x => x.PersonName) @Html.EditorFor(x=>x.OrderID) @Html.EditorFor(x => x