viewmodel

How to update Model when binding to a ViewModel?

◇◆丶佛笑我妖孽 提交于 2019-12-03 05:57:15
问题 I have an [HttpPost] action method signature like this: [HttpPost] public ActionResult Edit(ExistingPostViewModel model) { // Save the edited Post. } Now, in the past (when i didn't use ViewModels, e.g R&D), i had an implementation of an Edit method like this: [HttpPost] public ActionResult Edit(Post model) { var existingPost = repo.Find(model.Id); TryUpdateModel(existingPost); repo.Save(existingPost); return RedirectToAction("Success", existingPost.Id); } Which worked great. But i'm confused

Are current MVVM view model practices a violation of the Single Responsibility Principle?

こ雲淡風輕ζ 提交于 2019-12-03 05:49:16
问题 With current practices (at least with WPF and Silverlight) we see views bound via command bindings in the view model or we at least see view events handled in view models. This appears to be a violation of SRP because the view model doesn't just model the view state, but responds to the view (user). Others have asked how to build view models without violating SRP or asked whether their implementations do so (this last is the controller in MVC, but roughly analogous). So are current practices

Do i need to create automapper createmap both ways?

放肆的年华 提交于 2019-12-03 05:15:44
This might be a stupid question! (n00b to AutoMapper and time-short!) I want to use AutoMapper to map from EF4 entities to ViewModel classes. 1) If I call CreateMap<ModelClass, ViewModelClass>() then do I also need to call CreateMap<ViewModelClass, ModelClass>() to perform the reverse? 2) If two classes have the same property names, then do I need a CreateMap statement at all, or is this just for "specific/custom" mappings? In AutoMapper you have a Source type and a Destination type. So you will be able to map between this Source type and Destination type only if you have a corresponding

Does ASP.Net MVC 2 validation need some more thought in terms of patterns and use?

自古美人都是妖i 提交于 2019-12-03 05:06:27
问题 Here is the lay of the land. Like most people I have my domain object and I have my view models. I love the idea of using view models, as it allows for models to be created specifically for a given view context, without needing to alter my business objects. The problem I have is with type level validation defined on my domain object and getting those rules to the client. In this case lets say I am using data annotations to describe the validation rules, when I move the data from the domain

Using View-Models with Repository pattern

耗尽温柔 提交于 2019-12-03 04:57:35
问题 I'm using Domain driven N-layered application architecture with EF code first in my recent project, I defined my Repository contracts, In Domain layer. A basic contract to make other Repositories less verbose: public interface IRepository<TEntity, in TKey> where TEntity : class { TEntity GetById(TKey id); void Create(TEntity entity); void Update(TEntity entity); void Delete(TEntity entity); } And specialized Repositories per each Aggregation root , e.g: public interface IOrderRepository :

asp.net mvc models vs entity framework models

混江龙づ霸主 提交于 2019-12-03 03:15:35
Would it be best practice to create a model in your asp.net mvc - model folder. Use these models with your views and by using a service layer to "adapt" my model to the EF-model. Or have you used another approach. The problem with this approachs is that most of the times my (selfmade)model is a copy of the EF-model (not dry) So can someone explain me what models to use with your view cause it is becomming very confusing. model / viewmodel / Entityframeworkmodel .... Solution : Thanks for answers all guess i am at the moment to refactor some things! The correct approach is using different class

MVC Custom ViewModel and auto binding

家住魔仙堡 提交于 2019-12-03 03:13:19
I have a custom ViewModel defined as : public class SampleFormViewModel { public SampleFormViewModel(SelectList companies, Widget widget) { Companies = companies; Widget = widget; } public SelectList Companies { get; private set; } public Widget Widget { get; private set; } } In my Edit POST handler I have the following entry: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(SampleFormViewModel model) { Edit form is set up as: Inherits="System.Web.Mvc.ViewPage<Sample.Web.Models.SampleFormViewModel>" And it just blows up, not sure what’s going on, has the following error: No parameterless

Using MVVM in WPF, should I launch child windows from View code behind, or ViewModel?

若如初见. 提交于 2019-12-03 02:48:19
问题 I've been puzzled by this for a while. I am writing quite a large RibbonWindow WPF application using the MVVM pattern. The screen has a RibbonBar menu along the top and the rest of it displays the various Views. Some Views contain other Views and some of these have buttons that launch child Windows. So far, I have been doing this from the View code behind file, but I'm aware that these files are supposed to be empty when using MVVM. I could move the child window launch code to the ViewModel,

Building ViewModels based on nested Model Entities in WPF and MVVM Pattern

我与影子孤独终老i 提交于 2019-12-03 02:35:26
I have a problem understanding how to build view models based on the following models (I simplified the models to be clearer) public class Hit { public bool On { get; set;} public Track Track { get; set; } } public class Track { public ObservableCollection<Hit> Hits { get; set; } public LinearGradientBrush Color { get; set; } public Pattern Pattern { get; set; } } public class Pattern { public string Name { get; set; } public ObservableCollection<Tracks> Tracks { get; set; } } Now, my problem is, how to build the ViewModels.. I need to keep the original relationships through the models,

Bind to a Dictionary of Lists of Lists of Bools with a strongly-typed MVC view by using Checkboxes

北慕城南 提交于 2019-12-03 01:41:27
I'm using MVC 4, .Net 4, and Visual Studio 2012. I'm trying to use a fairly complex model with one of my views, and I'm having serious trouble getting it to bind properly. The model wraps a Dictionary with integer Keys, and Values that are Lists of Lists of bools. Basically, a search was done on items indicated by the integer, each item had several search terms, and for each of those terms we have a list of results. I display the results on a page, and have a checkbox next to each result. For each result, the user will indicate whether they want some stuff done by the next Action by checking