viewmodel

Is there a way to reuse data annotations?

老子叫甜甜 提交于 2019-12-06 07:23:04
问题 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;

Notify ViewModel when View is rendered/instantiated

大憨熊 提交于 2019-12-06 06:46:57
问题 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

ExtJs 5 grid store/viewmodel binding: Cannot modify ext-empty-store

放肆的年华 提交于 2019-12-06 06:27:53
I'm pulling my hair out on this one... I have a view with some grids, a store and a viewModel. I need different filtered versions of the store in different grids, so I'm trying to bind each filtered store to a grid. Now I can't even get a store to load in a grid in the first place... Here's what my code looks like: Store: Ext.define('My.store.Admin.Kinder', { extend: 'Ext.data.Store', model: 'My.model.Kind', storeId: 'adminKinderStore', alias: 'store.adminKinder', proxy: { type: 'ajax', method: 'post', url: '/getKinder', reader: { type: 'json', rootProperty: 'kinder' } } }); ViewModel: Ext

Change default “The {0} field is required” (ultimate solution?)

て烟熏妆下的殇ゞ 提交于 2019-12-06 06:14:54
Good day! I've the following ViewModel class I use for login form: using System.ComponentModel.DataAnnotations; ... public class UserLogin : IDataErrorInfo { [Required] [DisplayName("Login")] public string Login { get; set; } [Required] [DisplayName("Password")] public string Password { get; set; } [DisplayName("Remember Me")] public bool RememberMe { get; set; } #region IDataErrorInfo Members // This will be a Model-level error public string Error { get { if (!WebUser.CanLogin(Login, Password)) { return Resources.ValidationErrors.InvalidLoginPassword; } else { return String.Empty; } } } //

Hydrating ViewModels in ASP.NET MVC

牧云@^-^@ 提交于 2019-12-06 05:52:35
问题 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; }

ASP.NET MVC form handling unknown number of inputs

廉价感情. 提交于 2019-12-06 05:35:27
问题 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

Populate DropDownList in ASP.NET MVC from database table using Entity Framework 6 and ViewModel

拜拜、爱过 提交于 2019-12-06 05:03:09
问题 I have been scratching my head for a whole night on an issue I can do quickly using ajax/jquery and stored procedures. I want to 1) Populate a drop down list from values obtained from a database table using Entity Framework and view model. I DO NOT WANT TO USE VIEWBAG OR VIEWDATA. Any help appreciated. 2) How can I generate a Create View using the View Model with the all the default fields ? The scaffholding works on a model but not on a view model ? MY MODELS public class Employee { public

ViewModels and one-to-many relationships with Entity Framework in MVC?

血红的双手。 提交于 2019-12-06 04:44:54
问题 I have an application for storing information about consultants in a database. The model is an Entity Framework model, and the database tables are Consultant with one-to-many relationships to a number of other tables (WorkExperiences, Programs, CompetenceAreas, etc). Now, when I want to create a new Consultant object in a View, I would really just want to pass a Consultant object as the model to the View. But for one, it has been suggested to me (Collection of complex child objects in Asp.Net

Effectively avoiding ViewBag in ASP.NET MVC

▼魔方 西西 提交于 2019-12-06 03:32:25
问题 How do you deal with avoiding ViewBag due to its risk of error with being dynamic but also avoid having to populate a new ViewModel and pass it back to the view each time. For instance, I don't want to necessarily change the follow to expose common data normally stuffed in ViewBag. [HttpGet] void Index() { return View(); } to [HttpGet] void Index() { var messages = new MessageCollection(); messages.AddError("Uh oh!"); return View(messages); } Where in the pipeline would I add a property like

MVC architecture - re-using the same viewmodel for reads and edits

懵懂的女人 提交于 2019-12-06 02:41:04
问题 Say we have the following (overly simple) scenario: We have a screen to view person details and a screen to edit person details. The screen display person details has the following fields (as display only): First Name Last Name Bio The screen edit person details shows has following fields (in input controls): ID (hidden) First Name Last Name Bio Say our display viewmodel looks like this: public class DisplayPersonViewModel { public string FirstName { get; set; } public string LastName { get;