viewmodel

MVVM Child models and Navigation and beer

爱⌒轻易说出口 提交于 2019-12-30 05:19:10
问题 i was at the bar and i had couple beers, and this girl was arguing that getting mvvm to work with a real world applications is pain, she said that in order to solve problem in mvvm you add more code then you get another problem and the you add more code and it never ends, and i agree, when i read about mvvm it sounded nice, and i don't want to use prism nor MVVM light, i just need a way to switch between my views. and my application looks like this so please inspire me before i get alcohol

How to use Automapper to create complex viewmodel objects from a simple object and a method call

陌路散爱 提交于 2019-12-29 09:28:22
问题 My application needs to display a table of customer data, including data about the customer and about his most recent order from a given warehouse. The customer domain object contains a GetLatestOrder(warehouseId) method. I have a CustomerView viewmodel and want to be able to populate it with some fields from the customer object, and a few fields from the latest order object. Can I do this using Automapper? 回答1: Try this, In Global.asax.cs [ Application_Start ], public static void

MVC 3 form post and persisting model data

ε祈祈猫儿з 提交于 2019-12-28 09:14:11
问题 I think I'm missing some fundamentals on how MVC forms work. I have a search form on my home page that has five or six different fields a user can search on. So I have this POSTing to my results action just fine. The Result action looks like this: [HttpPost] public ActionResult Results(SearchModel model) { ResultsModel results = new ResultsModel(); results.ResultList = SearchManager.Search(model).ToList(); return View("Results", results); } I've simplified the above method for this post, but

Room - LiveData observer does not trigger when database is updated

怎甘沉沦 提交于 2019-12-28 04:12:06
问题 I am trying to find out in the code below, why is it that Room's LiveData observable does not give me new shifts once I populate the database with new data. This is put on my activity's onCreate method: shiftsViewModel = ViewModelProviders.of(this).get(ShiftsViewModel.class); shiftsViewModel .getShifts() .observe(this, this::populateAdapter); This is the populateAdapter method: private void populateAdapter(@NonNull final List<Shift> shifts){ recyclerView.setAdapter(new

Why Two Classes, View Model and Domain Model?

≡放荡痞女 提交于 2019-12-27 20:08:59
问题 I know it could be bad to use domain models as view models. If my domain model has a property named IsAdmin and I have a Create controller action to create users, someone could alter my form and get it to POST a IsAdmin=true form value, even if I did not expose such a text field in my view. If I'm using model binding then when I committed my domain model, that person would now be an admin. So the solution becomes exposing just the properties I need in the view model and using a tool like

Why Two Classes, View Model and Domain Model?

為{幸葍}努か 提交于 2019-12-27 20:06:25
问题 I know it could be bad to use domain models as view models. If my domain model has a property named IsAdmin and I have a Create controller action to create users, someone could alter my form and get it to POST a IsAdmin=true form value, even if I did not expose such a text field in my view. If I'm using model binding then when I committed my domain model, that person would now be an admin. So the solution becomes exposing just the properties I need in the view model and using a tool like

Why should I use view models?

假装没事ソ 提交于 2019-12-27 10:55:02
问题 I'm new to developing web apps using ASP.NET MVC. In fact, I'm rather new to developing web apps, regardless of technology. Currently, I'm working on a project just to get to know the ASP.NET MVC framework better. When reading on SO and elsewhere on the internet, the consensus seems to be that the views should never deal directly with the business objects (i.e. objects implementing business logic and containing associated attributes). Instead, view models should be used. However, this

How should posted data be modeled in MVC?

元气小坏坏 提交于 2019-12-25 17:19:34
问题 I think I get the idea of the ViewModel in MVC but, when doing updates and deletes, it seems like there should be a distinct model for posting to the controller. I noticed the default razor controllers use ViewBag to hold Selectlists. I guess that makes the ViewModel (domain entities really) reusable on the return trip because it is stripped of unnecessary data. But it seems like resorting to ViewBag doesn't make sense when using view models because the view model can contain the Selectlist s

Pulldown values not filled in in ViewModel

和自甴很熟 提交于 2019-12-25 09:01:45
问题 I am working through Hanselman's tutorial on MVC, and attempting to use a view model in the Create and Edit views so as to fill in a pulldown menu. In this we are directed to create a table Dinner , with columns including Title and Country and the related classes, and then a ViewModel containing a dinner object and a SelectList for a pull-down menu thus:- public class DinnerFormViewModel { public Dinner Dinner { get; private set; } public SelectList Countries { get; private set; } public

ASP.NET MVC 2.0 articles for ViewModel and partial view, Edit Templates, Validations and Custom Binders

女生的网名这么多〃 提交于 2019-12-25 08:16:14
问题 I am very confused and scratching my head. I am trying to implement a complex page with many partial Views and Nested ViewModels, but somehow i am not able complete because of my limited understanding of technology. Please help me in understanding the below topics from asp.NET MVC 2 by providing good article/tutorials 1. Partial Views 2. Nested ViewModel 3. Custom ViewModel Binders. I would really appreciate your help as right now i am trying to implement them without proper understanding and