viewmodel

Can you use nested view models in ASP.net MVC3?

﹥>﹥吖頭↗ 提交于 2019-12-10 06:57:37
问题 Here is a simplified version of what I am doing. I have created a view model that contains data for a Company. The company has 3 addresses. So trying to be clever I created an AddressViewModel and an _address partial. The problem I have is that while I can pass the AddressViewModel to the partial and it renders the address I now have duplicate id's in the HTML... so there are now three "Line1" input fields on the form which of course don't post back properly. How can I resolve this issue. Is

MVC3 How To Bind Multiple Checkboxes to 1 Property in ViewModel

本秂侑毒 提交于 2019-12-10 04:10:12
问题 I need to display a list of checkboxes, which more than one can be checked. When the user hits submit, the value of these checkboxes need to go into a property in the ViewModel...this is what I got so far... public class RegisterModel { public List<string> Roles { get; set; } public List<RoleModel> SelectedRoles { get; set; } } public class RoleModel { public string RoleName { get; set; } } In the view I am trying to do this... @foreach (var role in Model.Roles) { @Html.CheckBoxFor(m => m

ViewModel collection property lost values after posting back to controller action in MVC 3

杀马特。学长 韩版系。学妹 提交于 2019-12-10 03:19:22
问题 I have my view models : public class POReceiptViewModel { public virtual int PONumber { get; set; } public virtual string VendorCode { get; set; } public virtual IList<POReceiptItemViewModel> POReceiptItems { get; set; } public POReceiptViewModel() { POReceiptItems = new List<POReceiptItemViewModel>(); } } public class POReceiptItemViewModel { public virtual string ItemCode { get; set; } public virtual string ItemDesription { get; set; } public virtual decimal OrderedQuantity { get; set; }

Does ViewModel survive Activity save and restore?

放肆的年华 提交于 2019-12-10 00:58:57
问题 Instances of the new ViewModel class can survive configuration changes if used in the following fashion: mViewModel = ViewModelProviders.of(this).get(MyViewModel.class); However, in addition to configuration changes, there is also a save-restore scenario when the entire application's process is being killed. Will fields' values inside ViewModel be preserved during save-restore scenario? Edit: based on the answer to this question, I wrote this article: Android ViewModel Architecture Component

Communication between ViewModels

 ̄綄美尐妖づ 提交于 2019-12-09 23:34:12
问题 I have two questions regarding communication between ViewModels. I am developing a customer management program. I'm using Laurent Bugnion's MVVM Light framework. In the main page, there's a list of customers. when each customer is clicked, a child windows shows up with information about that customer. the user should be able to open up multiple child windows at the same time and compare information between customers. how do you pass customer object from the main page's ViewModel to the child

How to generate composed view models with temporary sub views?

笑着哭i 提交于 2019-12-09 21:39:41
问题 Scenario I have a quizz generator, which generates a sequence of quizzes of different classes. The sequence is of unlimited length. There is a view model for the quizz generator. There is a view model for each type of a quizz. The quizz generator view model should create the view models of the quizzes depending on their classes. Issue A view model must not hold a reference to the lifecycle, but I need the lifecycle to create view models. ViewModelProviders.of(lifecycle).get(classForQuizzType)

MVC4 C# Populating data in a viewmodel from database

蓝咒 提交于 2019-12-09 12:57:52
问题 I have a viewmodel which needs data from two models person and address: Models: public class Person { public int Id { get; set; } public string Name { get; set; } public int Age { get; set; } public int Gender { get; set; } } public class Address { public int Id { get; set; } public string Street { get; set; } public int Zip { get; set; } public int PersonId {get; set; } } The Viewmodel is as such public class PersonAddViewModel { public int Id { get; set; } public string Name { get; set; }

Where should ASP.NET MVC 2 validation go: in the model or viewmodel classes?

不问归期 提交于 2019-12-09 12:46:24
问题 I am using automapper to map my models to viewmodel classes to pass to my view. My question really is where should the validation go? I was planning on using the MetaData decorations - a feature of mvc 2. But either in the model or viewmodel? Or in both places? 回答1: Validation should be done minimum at the View Model because this is what you receive as action argument and contains the user input. You could also have validation at the model. 回答2: My answer would be ViewModel because Model can

How should I communicate between ViewModels?

折月煮酒 提交于 2019-12-09 10:50:06
问题 I am using MVVM Light and have used the packaged messenger system to communicate between view models, however I have hit a bit of a dilemma! Basically when a user clicks on a customer record the corresponding view is opened and with it the CustomerViewModel is instantiated. At this point the CustomerViewModel requires the selected customers ID from the previous view model ( ViewAllCustomersViewModel ) so that it can get selected customers info which the view binds to (still following?). So

ASP.NET MVC ViewModel with methods - is it “legal”?

故事扮演 提交于 2019-12-09 07:46:08
问题 Should viewmodels be limited to only have properties, and not methods? Let's say I have a radio button in my view, and wants to see if the radio button should be checked. I could do this entirely in my view: @Html.RadioButton("radiobuttonName", "The value", (id == Model.PersonId)) or I could move this logic into the viewmodel: @Html.RadioButton("radiobuttonName", "The value", Model.IsChecked(id) using this method in the viewmodel: public int PersonId { get;set;} public bool IsChecked(int id)