viewmodel

convert model to viewmodel [duplicate]

╄→尐↘猪︶ㄣ 提交于 2019-12-05 02:17:53
问题 This question already has answers here : Where to convert business model to view model? (3 answers) Closed 2 years ago . I have a table name "Product" and another table name "category". Product table has 'productID', 'productName' and 'CategoryID'. Category table has 'categoryID' and 'categoryName'. My target is to display a list of products with category. The list will contain 'product id', 'product name' and 'category name'. I have created a viewmodel. the code is public int prodID{get;set;

Shielding nullable domain properties with ViewModel

喜夏-厌秋 提交于 2019-12-05 02:16:53
问题 I am using Entity Framework 4.0, and making use of POCO objects. When I populate POCO objects from the DB, I translate property values to my own Domain objects, which we can call my Model. Necessarily, whether or not the fields of my Model are Nullable depends on whether the value it maps to in the database comes from a NULL or NOT NULL column. I won't go into detail, but the values must be nullable in the DB, because a user can partially save a draft of the object before publishing it to the

advice on architecting asp.net mvc applications

泪湿孤枕 提交于 2019-12-05 00:38:39
问题 I've been using ASP.net MVC for about two years now and I'm still learning the best way to structure an application. I wanted to throw out these ideas that I've gathered and see if they are "acceptable" ways in the community to design MVC applications. Here is my basic layout: DataAccess Project - Contains all repository classes, LINQ-to-SQL data contexts, Filters, and custom business objects for non-MS SQL db repositories (that LINQ-to-SQL doesn't create). The repositories typically only

AutoMapper - How to pass parameters into a Custom Resolver using ConstructedBy method?

有些话、适合烂在心里 提交于 2019-12-05 00:31:38
问题 In my ASP.NET MVC 2 (RC) project - I'm using AutoMapper to map between a Linq to Sql class (Media) and a view model (MediaVM). The view model has a SelectList property for a drop down in the view. I have a custom value resolver to populate the SelectList property items from the db, but am wondering if there's a way to pass a couple values from the source model into the resolver (using ConstructedBy method?) to a) define the selected item and b) filter the items from the db. The source object

AutoMapper: Why is UseValue only executed once

…衆ロ難τιáo~ 提交于 2019-12-04 23:15:33
Why is UseValue only executed once? I need to call the TeamRepository for each request. How can I achieve this? Mapping from TeamEmployee to TeamEmployeeInput: CreateMap<TeamEmployee, TeamEmployeeInput>() .ForMember(x => x.Teams, x => x.UseValue(GetTeamEmployeeInputs())) .ForMember(d => d.SelectedTeam, s => s.MapFrom(x => x.Team == null ? 0 : x.Team.Id)); private IEnumerable<TeamDropDownInput> GetTeamEmployeeInputs() { Team[] teams = CreateDependency<ITeamRepository>().GetAll(); return Mapper.Map<Team[], TeamDropDownInput[]>(teams); } Domain object: public class TeamEmployee : Entity { public

Possible bug in Html.DropDownList, selected values not reflecting?

时光怂恿深爱的人放手 提交于 2019-12-04 22:01:32
I know this has been asked a few times before, but the existing solutions look like hacks rather than a proper pattern. I have a simple drop down list. I am trying to populate it with data and have a item pre selected. I am succeeding at the 'populate it with data part' but failing to get my preferred item pre-selected. I am using ASP.NET MVC 3 RC2. The important code bits: { // Bunch of code CategoryOptions = new SelectList(categories, "Id", "Slug", article.Category.Id); } Now... the CategoryOptions is being passed to the Html helper like so: @Html.DropDownListFor(a => a.Category, Model

Updating a reference to a command of a nested ViewModel?

安稳与你 提交于 2019-12-04 21:58:08
I know I'm probably missing something simple and obvious, but at the moment it eludes me. I'm attempting to use the MVVM pattern. How do you update a reference to a command in a viewmodel that is linked to a child viewmodel? I've got a view (MainView) bound to a viewmodel (MainViewModel). On MainView, I've got an instance of another view (SummaryView) bound to a viewmodel (SummaryViewModel). SummaryViewModel contains a collection of a third viewmodel (SummaryFilterViewModel). On SummaryView, there is a TabControl and each tab on it is bound to one of the SummaryFilterViewModel instances in the

Let the ViewModel know the generic object of the View

白昼怎懂夜的黑 提交于 2019-12-04 20:46:57
I have a generic view where I "inject" some specific view into a contained ContentControl (I created that feature with these help -> help 1 - help 2 ). The basic source of my views are these: MyGenericView.xaml <UserControl x:Class="MyNS.MyGenericView" ... > <UserControl.Resources> <vml:ViewModelLocator x:Key="Locator" d:IsDataSource="True" /> </UserControl.Resources> <Grid DataContext="{Binding MyGenericViewModel, Source={StaticResource Locator}}"> <ContentControl Content="{Binding MyObject}" /> </Grid> </UserControl> CustomerView.xaml <UserControl x:Class="AnotherNS.CustomerView" ... > <Grid

Databinding 2 comboboxes Issue

喜欢而已 提交于 2019-12-04 19:40:31
I have 2 comboboxes. If i select a Activity in the 1st one, the related sub activities should be displayed in the second combobox. The code looks fine as per MVVM style but when i select an activity on 1st one, the related subactivities in the 2nd combobox are not synched. Here is my code: View <Window x:Class="TestDGCombosBinding.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:TestDGCombosBinding" Title="MainWindow" Height="350" Width="525"> <Grid> <Grid.Resources>

Implementing ASP.NET MVC 3 Interface Model Binding (with ViewModel)

两盒软妹~` 提交于 2019-12-04 18:43:37
I just learning ASP.NET MVC 3 and I'm a bit confused on how I can implement something like what is shown in this link: http://www.codethinked.com/easy-and-safe-model-binding-in-aspnet-mvc Why I'm confused is most likely based on my ignorance in the subject. In the example on the page linked above, I see Justin is using a ViewModel that directly contains properties of his "Person" object. What I want to do is similar, but I want to have a ViewModel actually contain the domain class, which is in my case Company, rather than Person. I'm having the Company class itself implement the ViewModel