viewmodel

How to get data for a dropdownlist into viewmodel when using AutoMapper/AutoMapViewResult

拜拜、爱过 提交于 2019-11-27 14:02:11
问题 After reading ASP.NET MVC 2 in Action and watching Jimmy Bogard's presentation from MvcConf (both highly recommended!), I began to implement some of their ideas. One of the cool things they do, is not only to use AutoMapper to map your entities to some viewmodel, but automate this with an AutoMapViewResult: public class EventsController : BaseController { public ActionResult Show(Event id) // EntityModelBinder gets Event from repository { return AutoMapView<EventsShowModel>(id); //

How to handle custom Properties in AutoMapper

孤者浪人 提交于 2019-11-27 13:40:14
问题 I've got a ViewModel that takes some Model data and slightly alters it. The way I'm doing it "works" since I just pass the DomainModel to the constructor for the ViewModel , but since I'm using AutoMapper on some of my one-to-one ViewModels, I thought I'd try and learn how to do the mapping across all ViewModels. Here's an example of a ViewModel that does a little extra. public class UsersDetailsViewModel { public string UserName { get; set; } public string Email { get; set; } public string

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

时光怂恿深爱的人放手 提交于 2019-11-27 13:32:01
问题 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

ASP.NET MVC: using EF entities as viewmodels? [duplicate]

旧巷老猫 提交于 2019-11-27 13:16:21
Possible Duplicate: ASP.NET MVC - Linq to Entities model as the ViewModel - is this good practice? Is is OK to use EF entities classes as view models in ASP.NET MVC? What if viewmodel is 90% the same of EF entity class? Let's say I have a Survey class in Entity Framework model. It 90% matches data required for view to edit it. The only difference from what view model should have - is one or several properties to be used in it (that are required to populate Survey object because EF class cannot be directly mapped onto how it's properties are represented (sub-checkboxes, radio groups, etc.)) Do

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

ε祈祈猫儿з 提交于 2019-11-27 11:29:48
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 from the master page's ViewModel . Question How should a child controller ensure that the master page's data is passed to the View without setting the properties of its ViewModel that pertain to the master page itself? My the master page will display a number of

How can I bind nested ViewModels from View to Controller in MVC3?

萝らか妹 提交于 2019-11-27 11:15:01
I am developing an ASP.NET MVC 3 application in C# and I use Razor. I am now dealing with a problem concerning the binding of objects through ViewModels passed/received to/from the View by the Controller. Let's make it clear. I have the following ViewModels: public class ContainerViewModel { public int ContainerId {get; set;} public string ContainerName {get; set;} public List<ItemPostModel> ItemData {get; set;} } public class ItemPostModel { public int ItemId {get; set;} public string ItemName {get; set;} public int ItemValue {get; set;} } The ContainerViewModel is used to pass the data to

MVVM load data during or after ViewModel construction?

这一生的挚爱 提交于 2019-11-27 10:51:20
问题 My generic question is as the title states, is it best to load data during ViewModel construction or afterward through some Loaded event handling? I'm guessing the answer is after construction via some Loaded event handling, but I'm wondering how that is most cleanly coordinated between ViewModel and View? Here's more details about my situation and the particular problem I'm trying to solve: I am using the MVVM Light framework as well as Unity for DI. I have some nested Views, each bound to a

Custom vs User control

拈花ヽ惹草 提交于 2019-11-27 10:29:40
I've been reading some explanations about the difference between User and Custom Controls, for example this: http://www.wpftutorial.net/CustomVsUserControl.html I want to create, for example, a simple composition of a datagrid with 2 comboboxes which are responsible to change the values from the datagrid's items. I want to create a specific control for this because I'm going to use it a lot of times. I would like to implement the logic behind and then in the xaml invocation I only have to specify the itemsSource. For this example should I create a User or Custom control? Since I will have

Mapping Validation Attributes From Domain Entity to DTO

萝らか妹 提交于 2019-11-27 10:20:24
问题 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

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

别来无恙 提交于 2019-11-27 08:50:56
问题 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