viewmodel

How do you ignore/persist values in MVC when your view-model doesn't have as many fields as your domain model?

与世无争的帅哥 提交于 2019-12-07 03:52:29
问题 I have a site where I'm using fluentNhibernate and Asp.net MVC. I have an Edit view that allows user to edit 8 of the 10 properties for that record (object). When you submit the form and the Model binds, the two un-editable fields come back in the view-model as Empty strings or as default DateTime values depending on the type of property. Because I'm also using AutoMapper to map my view-model to my Domain Entity, I cannot just load a fresh copy of my object from the database and manually set

How come internal members in my view model aren't accessible in the view?

我的未来我决定 提交于 2019-12-07 03:09:47
问题 I have some internal automatic properties in my view model but my strongly-typed view doesn't see them. Everything is in the same assembly, so why is this happening? public class MyViewModel { public int PublicProperty { get; set; } internal int InternalProperty { get; set; } } . @*My view*@ @model MyViewModel @Model.PublicProperty @Model.InternalProperty @*Causes compilation error*@ 回答1: Views are compiled in a separate dynamically generated assembly by the ASP.NET runtime. So you cannot use

ASP.NET MVC Complex View Mapping

血红的双手。 提交于 2019-12-07 00:36:30
I have looked around and found some close answers, but I haven't seen one yet like this: Using Entity Framework I have the following: A Role model: public class Role { [Key] public short RoleId { get; set; } public string RoleName { get; set; } public string RoleDescription { get; set; } } A User model: public class User { public int Id { get; set; } public string Name { get; set; } public string Email { get; set; } public string Username { get; set; } //more fields etc... public virtual ICollection<UserRole> UserRoles { get; set; } } and a UserRole model: public class UserRole { [Key] public

Windows Phone 8 - MVVM ViewModels and App.xaml.cs

自闭症网瘾萝莉.ら 提交于 2019-12-07 00:28:36
问题 I've been studying the MVVM pattern and putting it into practice in a Windows Phone 8 app, and I have a question about the best practices for initializing and accessing ViewModels in an app. When I create a Databound Application from the WP8 SDKs templates, I noticed this code in the App.xaml.cs file: public static MainViewModel ViewModel { get { // Delay creation of the view model until necessary if (viewModel == null) viewModel = new MainViewModel(); return viewModel; } } private void

When should I be using AutoMapper and when not

时光怂恿深爱的人放手 提交于 2019-12-07 00:00:51
问题 I have a Data layer which holds my EF6 DbFirst edmx, repositories, and AutoMappings. I also have a Model layer with a Poco for each auto generated entity in my Data layer. The properties pretty much match exactly except for a few name changes. AutoMapper is installed to my DataLayer only and this is where I set all of my mappings in a config file. At this point I have a mapping from each DataLayer entity to each ModelLayer entity and each ModelLayer entity to each DataLayer entity. Any name

AutoMapper: Why is UseValue only executed once

China☆狼群 提交于 2019-12-06 17:43:38
问题 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

Why is this View not correctly binding to this ViewModel?

Deadly 提交于 2019-12-06 16:29:00
I'm trying to bind my view to my view model without DataObjectProvider. The following code runs without an error , but my ListBox is empty . As far as I can tell, I correctly: set the View's DataContext to the ViewModel itself ( DataContext = new CustomersViewModel(); ) expose the customer objects in the ViewModel ( public static ObservableCollection<Customer> GetAll() ) bind the ListBox to the customer objects ( ItemsSource="{Binding GetAll}" ) What little piece of syntax am I missing here? CustomersView.xaml: <UserControl x:Class="TestDynamicForm123.View.CustomersView" xmlns="http://schemas

ASP.NET MVC, Model and ViewModel separation of concerns?

烂漫一生 提交于 2019-12-06 16:02:08
问题 Lately, I've been exploring what's the best way to organize presentation layer of ASP.NET MVC application when underlying Model is complex. What came up till now is MVVM architecture with their ViewModel objects. However, I'm not sure what are the best practices when this kind of architecture is in case. Does ViewModel objects can contain Model objects? If MVVM used, is it advisable that Model objects are used on Views? Where validation should be implemented, on ViewModel or Model classes?

Let the ViewModel know the generic object of the View

£可爱£侵袭症+ 提交于 2019-12-06 15:24:53
问题 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}"

ASP MVC 3 Two Models in One View

回眸只為那壹抹淺笑 提交于 2019-12-06 14:55:43
I am working on creating a datagrid in ASP MVC 3 where I have two tables in one view. Each table is being used from its own Model. Therefore, I would have to call two Models into one View which does not seem as simple as I wish it was. I am pretty new to MVC and I was looking through Stack and found this link: Two models in one view in ASP MVC 3 Which seems to be the direction that i would want to go... I think. Here is the code for my first model: [Table] public class Model1 { [Column(IsPrimaryKey = true, IsDbGenerated = true)] public int Column1 { get; set; } [Column] public string Column2 {