modelmetadataprovider

Configure Custom MetadataProvider for ViewModel

爱⌒轻易说出口 提交于 2020-01-14 04:21:26
问题 I have a ViewModel for which want to be able to set Metadata properties dynamically. For example I would like to be able to customise the DisplayName and validation error messages using the value of other model properties. I plan to do this with a custom MetadataProvider, following Brad Wilson's article. I want the provider only to be used with selected ViewModels. So my question is, how do I configure that? I have seen examples using ModelMetadataProviders.Current = new

Add new Property to MVC ModelMetadata

时光毁灭记忆、已成空白 提交于 2019-12-12 11:43:20
问题 I'm seeing alternative approaches to this such as AdditionalValues, but I'm wondering if it's possible to end up in a scenario where you can add a new property to the ModelMetadata object available in template views. For example you could have: @ViewData.ModelMetadata.MvvmBound I want to use this in Editor and Display templates to add MVVM attributes to the HTML elements being rendered. I'm completely lost, but here are my efforts so far: public class MyModelMetaDataProvider :

How to Transfer DataAnnotation metadata to ViewModel with AutoMapper with Betty's Approach

梦想与她 提交于 2019-12-09 18:31:44
问题 I need clarification on how to implement Betty's code solution to transferring data annotation metadata to ViewModels with AutoMapper (see here). Or if you have a better way, please share that. Maybe the implementation of Betty's answer is obvious to someone who knows AutoMapper well, but I'm new to it. Here is a simple example, what do I add to this code to make Betty's solution work: // Data model Entity public class User1 { [Required] public int Id { get; set; } [Required] [StringLength(60

How to add MetaData to a dynamically build MVC3 ViewModel?

南楼画角 提交于 2019-12-08 05:12:54
问题 One of the key features of a project I'm working on is the ability for the user to configure Forms (as in "Forms" to fill-up) based on a pool of pre-existing field types (well known types, for instance "user name", "date of birth" etc. but also "generic types" like "string", "DateTime" etc.). We used to have a static ViewModel that worked fine for the "well known" types and looked like this: public class UserInputModel { [StringLength(200)] public string Name { get; set; } [Required

Configure Custom MetadataProvider for ViewModel

不打扰是莪最后的温柔 提交于 2019-12-07 23:44:30
I have a ViewModel for which want to be able to set Metadata properties dynamically. For example I would like to be able to customise the DisplayName and validation error messages using the value of other model properties. I plan to do this with a custom MetadataProvider, following Brad Wilson's article . I want the provider only to be used with selected ViewModels. So my question is, how do I configure that? I have seen examples using ModelMetadataProviders.Current = new MyModelMetadataProvider() , but this would presumably use the custom provider for all model classes entities. Is it

Technique for carrying metadata to View Models with AutoMapper

◇◆丶佛笑我妖孽 提交于 2019-12-06 05:50:07
问题 I use AutoMapper to map my domain objects to my view models. I have metadata in my domain layer, that I would like to carry over to the view layer and into ModelMetadata. (This metadata is not UI logic, but provides necessary information to my views). Right now, my solution is to use a separate MetadataProvider (independently of ASP.NET MVC), and use conventions to apply the relevant metadata to the ModelMetadata object via an AssociatedMetadataProvider. The problem with this approach is that

How to Transfer DataAnnotation metadata to ViewModel with AutoMapper with Betty's Approach

大兔子大兔子 提交于 2019-12-04 08:54:02
I need clarification on how to implement Betty's code solution to transferring data annotation metadata to ViewModels with AutoMapper (see here ). Or if you have a better way, please share that. Maybe the implementation of Betty's answer is obvious to someone who knows AutoMapper well, but I'm new to it. Here is a simple example, what do I add to this code to make Betty's solution work: // Data model Entity public class User1 { [Required] public int Id { get; set; } [Required] [StringLength(60)] public string FirstName { get; set; } [Required] [StringLength(60)] public string LastName { get;

Technique for carrying metadata to View Models with AutoMapper

北慕城南 提交于 2019-11-27 17:45:20
I use AutoMapper to map my domain objects to my view models. I have metadata in my domain layer, that I would like to carry over to the view layer and into ModelMetadata. (This metadata is not UI logic, but provides necessary information to my views). Right now, my solution is to use a separate MetadataProvider (independently of ASP.NET MVC), and use conventions to apply the relevant metadata to the ModelMetadata object via an AssociatedMetadataProvider. The problem with this approach is that I have to test for the same conventions when binding the ModelMetadata from the domain as I do with my

Technique for carrying metadata to View Models with AutoMapper

纵然是瞬间 提交于 2019-11-26 22:37:02
问题 I use AutoMapper to map my domain objects to my view models. I have metadata in my domain layer, that I would like to carry over to the view layer and into ModelMetadata. (This metadata is not UI logic, but provides necessary information to my views). Right now, my solution is to use a separate MetadataProvider (independently of ASP.NET MVC), and use conventions to apply the relevant metadata to the ModelMetadata object via an AssociatedMetadataProvider. The problem with this approach is that