viewmodel

Automapper Mapping IEnumerable<SelectListItem> for Dropdown Menu

*爱你&永不变心* 提交于 2019-12-04 16:05:02
Problem I am currently adding automapping to my MVC project and I am stuck. Right now I have a User model used to represent data in the database. I have to map that model to a EditUserModel which will be used when the Edit method is called. The EditUserModel has IEnumerable<SelectListItem> (for a dropdown menu) that I can't seem to figure out how to map. Attempted Solution As of right now I haven't tried to implement anything. I am unsure where the best place for the IEnumerable<SelectListItem> or where to populate it. Right now it is being populated in the Controller. User.cs public class

Passing ViewModel in ASP.Net MVC from a View to a different View using Get

守給你的承諾、 提交于 2019-12-04 15:59:45
I have a List View which has a strongly typed ViewModel which includes the entity list I am working with together with some other session-type stuff I am carrying aruound. On clicking an item in the list (an Html.ActionLink) to go to the Details view I can easily pass the entity id. But I also want to pass the rest of the ViewModel from the View. I can build the ActionLink with various QueryString parameters and then a custom ModelBinder can pick them up and hydrate the ViewModel object for me again. However, I don´t like this. I can get the custom ViewModel to rehydrate when it is POSTed back

How to generate composed view models with temporary sub views?

旧时模样 提交于 2019-12-04 15:29:40
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); Questions Where do I create the sub view models of the quizzes? The one solution I can think of is to

Is there a way to reuse data annotations?

戏子无情 提交于 2019-12-04 14:44:13
Is there a way to implement the idea of a data domains (at a property level) inside of a class that is used as a model in a view in ASP.Net MVC 4? Consider this code: public class LoginProfileModel { [DisplayName("Login ID")] [Required(ErrorMessage = "Login ID is required.")] public string LogonID { get; set; } [DisplayName("Password")] [Required(ErrorMessage = "Password cannot be blank.")] [StringLength(20, MinimumLength = 3)] [DataType(DataType.Password)] public string Password { get; set; } } Here is a LoginProfileModel in for ASP.Net MVC 4. It uses a variety of metadata/data annotations so

DRY vs Security and Maintainability with MVC and View Models

a 夏天 提交于 2019-12-04 12:14:04
问题 I like to strive for DRY, and obviously it's not always possible. However, I have to scratch my head over a concept that seems pretty common in MVC, that of the "View Model". The View Model is designed to only pass the minimum amount of information to the view, for both security, maintainability, and testing concerns. I get that. It makes sense. However, from a DRY perspective, a View Model is simply duplicating data you already have. The View Model may be temporary, and used only as a DTO,

ASP.NET MVC form handling unknown number of inputs

半腔热情 提交于 2019-12-04 12:12:42
I'm building an internal page that allows trusted users to change a parameter setup manually through a form. The inputs to this setup are a list of setupparameters (of unknown size), each with a specific list of values. The user can then select a value for all or a subset of the parameters. I have attempted to illustrate this with my current model for the view public class SetupModel { public List<SetupParameter> Parameters { get; set; } } public class SetupParameter { public string ParameterName { get; set; } // list with text=paramvalue, value=paramvalueid public SelectList

ASP.NET MVC - Should I use the Repository Pattern to write ViewModels to the database or convert them to Models first?

喜夏-厌秋 提交于 2019-12-04 11:50:34
问题 In my ASP.NET MVC app, I have a fairly complex edit page which combines a number of models into one view. I'm using the ViewModel pattern to combine all of this information and present one cohesive object to the View. As an example, my ViewModel structure is something like this: CompanyId CompanyName List<Employee> Employees List<ContactMethod> ContactMethods The Employee object has a number of basic properties, and a preferred contact method. On the edit page, the user is given all of the

Hydrating ViewModels in ASP.NET MVC

我们两清 提交于 2019-12-04 11:19:11
I have a page that is made up of many user controls. The view model for this page is rather complex. public class ComplexViewModel { public ObjectA ObjectAProperty { get; set; } public List<Things> ListOfThings { get; set; } public List<ThingCategories> ListOfThingCategories { get; set; } public List<ThingTypes> ListOfThingTypes { get; set; } public List<ThingOptions> ListOfThingOptions { get; set; } public int ChosenThingCategoryId { get; set; } public int ChosenThingTypeId { get; set; } public int ChosenThingOptionId { get; set; } public OtherObject ObjectData { get; set; } } This page also

Select() Input Field with Knockout.js

这一生的挚爱 提交于 2019-12-04 10:38:11
问题 I am new to Knockout.js. What is the best way to select() an <input /> when it becomes visible? View: <p> Name: <b data-bind="visible: !editing(), text: name, click: edit"> </b> <input data-bind="visible: editing, value: name, hasfocus: editing" /> </p> ViewModel: function PersonViewModel(name) { // Data this.name = ko.observable(name); this.editing = ko.observable(false); // Behaviors this.edit = function() { this.editing(true) } } ko.applyBindings(new PersonViewModel("Bert Bertington"));

Notify ViewModel when View is rendered/instantiated

自古美人都是妖i 提交于 2019-12-04 10:31:15
I have a custom usercontrol ( ChartControl ) that I use within my WPF app ( MainApp ) and which I render as follows: <ContentControl Grid.Row="1" Content="{Binding ChartControl, Mode=OneWay}" /> Upon starting MainApp the following are executed in the given order: MainApp View MainApp ViewModel ChartControl ViewModel ChartControl View I instantiate the ChartControl ViewModel from within the constructor of my MainApp ViewModel. The problem is that after instantiating the ChartControl ViewModel I also need to call a method of ChartControl from within MainApp . The problem I am having is that I