viewmodel

Designing an MVC repository using ViewModels

孤街醉人 提交于 2019-12-03 01:33:06
I want to create a repository class to separate out my data logic from my controllers. I am using a ViewModel to represent some data that will be filled with data from different tables. Here are some questions I have: For a method like GetAll() , do I return an IQueryable<MyViewModel> or IQueryable<Entity> ? If I return viewmodels, how do I cope with a GetAll() that pulls thousands of records? Do I create a constructor for my custom ViewModel class that takes the Entity as a parameter to do the mapping? (I'm still unfamiliar with automapper so just need an understanding on how to do this from

How are you populating/validating your ViewModels?

跟風遠走 提交于 2019-12-03 00:53:40
问题 I'm curious of all of the various ways people are building their ViewModels and why they choose that method. I can think of several ways here: -1. Injected repository - the controller loads the model and maps to the ViewModel. Here the ViewModel constructor could take various collections to interally set for ex. in a select list such as: public CustomerController(ISomeRepository repository) { _repository = repository; } public ActionResult Create() { CustomerCreateViewModel model = new

Need to pass initial viewmodel data from ASP.NET MVC to knockout.js

╄→гoц情女王★ 提交于 2019-12-03 00:34:07
I was looking at the Contacts editor sample on the knockout.js website: http://knockoutjs.com/examples/contactsEditor.html The sample works perfectly, but I needed to make two changes to it: Pass the initial data from ASP.NET MVC 3 controller action method. Here is the code from the server: Classes public class Phone { public string Type { get; set; } public string Number { get; set; } } public class Person { public string FirstName { get; set; } public string LastName { get; set; } public List<Phone> Phones { get; set; } } Sample Controller side code List<Phone> phoneList = new List<Phone>();

MVC Dynamic View Data and Dynamic Views

旧巷老猫 提交于 2019-12-02 21:28:44
Traditionally, I have built MVC applications using view models with Data Annotations attributes, and I dynamically render the views using editor templates. Everything works great, and it really cuts down on the time it takes me to build new views. My requirements have recently changed. Now, I can't define the view model at design time. The properties that will be rendered on the view are decided at run time based on business rules. Also, the validation rules for those properties may be decided at run time as well. (A field that is not required in my domain model, may be required in my view

WPF MVVM Unit Tests for the ViewModel? [closed]

别等时光非礼了梦想. 提交于 2019-12-02 20:14:53
Closed. This question is off-topic. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it's on-topic for Stack Overflow. I keep reading about the benefits of using MVVM, especially for unit testing. So, now I need to write unit tests for my ViewModel. Does anyone have any examples of this? Should I just generate the unit tests using VS2008 and select those tests that appear important? 来源: https://stackoverflow.com/questions/1441534/wpf-mvvm-unit-tests-for-the-viewmodel

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

穿精又带淫゛_ 提交于 2019-12-02 19:09:30
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 a violation of SRP? Or is "view model" really a collection of things that don't violate SRP? To frame

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

有些话、适合烂在心里 提交于 2019-12-02 18:19:12
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 object to the view model, the view model no longer knows what validation it should get the interface to

Using View-Models with Repository pattern

╄→гoц情女王★ 提交于 2019-12-02 18:14:24
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 : IRepository<Order, int> { IEnumerable<Order> FindAllOrders(); IEnumerable<Order> Find(string text); /

Creating a dropdown in MVC3 C# with ViewModel and easy model binding on POST back.

廉价感情. 提交于 2019-12-02 16:50:14
问题 I have this problem where i want to make 7 dropdowns for each day of the week. In each one of those dropdowns i wish to add the same data. My ViewModel: public class WeekDienstCreateViewModel { public WeekDienst weekDienst {get; set;} public List<DienstPerWeekDienst> diensten { get; set; } public WeekDienstCreateViewModel() { } } My Create Method in Controller: As u can see I add everything allready except DienstId which is want to add with my dropdowns. public ActionResult Create(int id) {

How are you populating/validating your ViewModels?

假装没事ソ 提交于 2019-12-02 14:18:10
I'm curious of all of the various ways people are building their ViewModels and why they choose that method. I can think of several ways here: -1. Injected repository - the controller loads the model and maps to the ViewModel. Here the ViewModel constructor could take various collections to interally set for ex. in a select list such as: public CustomerController(ISomeRepository repository) { _repository = repository; } public ActionResult Create() { CustomerCreateViewModel model = new CustomerCreateViewModel(_repository.GetShipTypes, _repository.GetStates); .. .. } -2. ViewModelBuilder -