viewmodel

asp.net MVC should a View-Model Encapsulate Domain-Model?

房东的猫 提交于 2019-12-01 04:26:23
问题 I've see a lot of MVC examples where domain-objects are passed directly to views, this will work fine if your view is simple. The common alternative is to have a view-model which has all the same properties as your domain-model + any extra properties your view may need (such as 'confirmPassword'). Before doing too much reading and before discovering AutoMapper I started creating my own variant of view-model where the domain-object (or multiple domain objects) are simply properties of the view

ASP.NET MVC - Linq to Entities model as the ViewModel - is this good practice? [closed]

杀马特。学长 韩版系。学妹 提交于 2019-12-01 03:44:58
Quick questions really. I am currently building a site using asp.net MVC and the entity framework. I have a couple of repositories in place which return entities or lists of entities. I am finding that in the majority of my pages I'm having to pull data from a variety of related tables. This is ok so long as I load up the related entities using 'include' in my queries - but is this good practice? Would it be better to create a custom viewmodel object that contains just the bits of info I need, or is there nothing 'wrong' with pulling an object graph that is perhaps 5 - 6 tables deep just to

When is it right to use ViewData instead of ViewModels?

馋奶兔 提交于 2019-12-01 03:29:48
Assuming you wanted to develop your Controllers so that you use a ViewModel to contain data for the Views you render, should all data be contained within the ViewModel? What conditions would it be ok to bypass the ViewModel? The reason I ask is I'm in a position where some of the code is using ViewData and some is using the ViewModel. I want to distribute a set of guidelines in the team on when it's right to use the ViewData, and when it's just taking shortcuts. I would like opinions from other developers who have dealt with this so that I know my guidelines aren't just me being biased. Just

e: [kapt] An exception occurred: android.databinding.tool.util.LoggedErrorException: Found data binding errors

老子叫甜甜 提交于 2019-12-01 03:12:49
I have enabled databinding, but while I execute the code I get this error. error e: [kapt] An exception occurred: android.databinding.tool.util.LoggedErrorException: Found data binding errors. I created a fragment class and XML for that class. Im able to import datbindingutil class. I have done rebuilt/ sync with gradle files/ invalidate cache and restart, nothing worked. xml <layout> <!--suppress AndroidUnknownAttribute --> <data class=".databinding.ProfileFragmentBinding"> <variable name="user" type="com.sample.sample.user.User" /> <variable name="vm" type="com.sample.sample.user

ASP.NET MVC - Linq to Entities model as the ViewModel - is this good practice? [closed]

天大地大妈咪最大 提交于 2019-12-01 00:51:51
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . Quick questions really. I am currently building a site using asp.net MVC and the entity framework. I have a couple of repositories in place which return entities or lists of entities. I am finding that in the majority of my pages I'm having to pull data from a variety of

How do I ModelBind a many-to-many relationship with MVC 3 and Entity Framework Code First?

空扰寡人 提交于 2019-11-30 23:46:01
I'm coming across the same problem in my MVC 3 applications. I've got a view to create an new product and that product can be assigned to one or more categories. Here are my EF Code First Model Classes: public class Product { public int ProductID { get; set; } public string Name { get; set; } public virtual ICollection<Category> Categories { get; set; } } public class Category { public int CategoryID { get; set; } public string Name { get; set; } public virtual ICollection<Product> Products { get; set; } } So, I create a view model for the create product view and include the product and a list

Binding collections in MVC

人盡茶涼 提交于 2019-11-30 23:15:07
I have a View Model that consists of an Applicant object and a TeamMember collection. When I post the model back the Team collection is always null. I've tried changing the collection from my original IEnumarable to a List but that didn't make a difference. So I changed the Controllers Edit Action to accept the FormCollection , and verified there was data in viewModel["member.FirstName"] . I'm lost as to why the binding isn't working. I tried to clean out my code samples as much as possible but I'm confused at what I'm missing. Any help is greatly appreciated! View Model Properties public

e: [kapt] An exception occurred: android.databinding.tool.util.LoggedErrorException: Found data binding errors

梦想与她 提交于 2019-11-30 23:02:35
问题 I have enabled databinding, but while I execute the code I get this error. error e: [kapt] An exception occurred: android.databinding.tool.util.LoggedErrorException: Found data binding errors. I created a fragment class and XML for that class. Im able to import datbindingutil class. I have done rebuilt/ sync with gradle files/ invalidate cache and restart, nothing worked. xml <layout> <!--suppress AndroidUnknownAttribute --> <data class=".databinding.ProfileFragmentBinding"> <variable name=

ASP.NET MVC ViewModel and DropDownList

本小妞迷上赌 提交于 2019-11-30 21:30:07
I have 2 properties in my ViewModel class ViewModel1 { Dictonary<int, string> PossibleValues {get;set;}//key/value int SelectedKey {get;set} } I want to edit this using a Html.DropDownListFor I want to get MVC to auto serialize the data into/from the ViewModel so I can the following public ActionResult Edit(ViewModel1 model) ... What's the best way to accomplish this? David Glenn As womp said, a browser will only submit the selected value of a drop down list. This is easily bound by the default model binder, see below. If you are not editing the PossibleValues list on the client then there is

ASP.NET MVC: Nesting ViewModels within each other, antipattern or no?

独自空忆成欢 提交于 2019-11-30 21:23:44
I have a project where ViewModels are nested within each other such that they essentially are a string-typed replication of the domain hierarchy. For example, if our domain has the following relationships: Organization has 1 to many Environments Environment has 1 to many Machines then there will be an OrganizationViewModel that has one to many EnvironmentViewModels in it, and the EnvironmentViewModel will have one to many MachineViewModels themselves. This style of hierarchy is then reused throughout the app, with one of about five ViewModels of this type. (e.g. EnvironmentViewModel is used