modelmetadata

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 do I get the the fully qualified member name in an EditorTemplate?

大憨熊 提交于 2019-12-06 05:43:38
问题 I have an ASP.NET MVC 4 site and I am passing a nested property to an EditorTemplate and building the field name using ViewData.ModelMetadata.PropertyName however, this gets the property name of the child property, not the full dot-notation name of the property I'm editing. An example will illustrate best: Given the following types public class EditEntityViewModel { // elided public Entity Entity { get; set} } public class Entity { // elided public string ImageUrl { get; set; } } My Edit and

ModelMetadata for complex type in editortemplate in asp.net mvc

送分小仙女□ 提交于 2019-12-06 02:57:19
问题 I have a viewmodel that includes a complex property of type TestThing which is declared as: public class TestThing { [Display(Name = "String3", Prompt = "String4")] public string Test1 { get; set; } [Display(Name = "String5", Prompt = "String6")] public string Test2 { get; set; } } I have an EditorTemplate for this type in which I would like to be able to access the meta data for each of the child properties. If the template was for a string for example, I could access the Prompt text by

How can I extend CachedDataAnnotationsModelMetadataProvider?

♀尐吖头ヾ 提交于 2019-12-05 18:20:53
We are looking to use CachedDataAnnotationsModelMetadataProvider as it improves performance and we use a lot of Meta Data in our MVC4 application. We are currently creating a custom ModelMetadataProvider inheriting from DataAnnotationsModelMetadataProvider and overriding CreateMetadata attribute to do some automatic display name creation e.g. remove Id from names etc. However we also want to cache it so we wanted to base our custom ModelMetadataProvider on CachedDataAnnotationsModelMetadataProvider. If we try to override CreateMetadata we can't as it is sealed. Any reason it is sealed - I

ASP.NET MVC3 WebGrid Helper and Model Metadata

♀尐吖头ヾ 提交于 2019-12-05 17:47:32
I'm trying to use the WebGrid html helper in ASP.NET MVC 3 to autogenerate the columns according to the information found in the ModelMetadata. For example the code in a view that accepts a list of objects would be: var grid = new WebGrid(Model); @grid.GetHtml(columns: ViewData.ModelMetadata.Properties.Single.Properties .Select(p => grid.Column( columnName: p.PropertyName, header: p.ShortDisplayName ))); This actually works like a charm (I was surprised it was that easy actually). What happens here is that from the properties of the model I use the ShortDisplayName as the column's header. The

ModelMetaData, Custom Class Attributes and an indescribable question

感情迁移 提交于 2019-12-04 13:29:41
问题 What I want to do seems so simple. In my index.cshtml I want to display the WizardStepAttribute Value So, a user will see at the top of each page, Step 1: Enter User Information I have a ViewModel called WizardViewModel . This ViewModel has a property that is IList<IStepViewModel> Steps each "step" implements the Interface IStepViewModel, which is an empty interface. I have a view called Index.cshtml. This view displays EditorFor() the current step. I have a custom ModelBinder, that binds the

How do I get the the fully qualified member name in an EditorTemplate?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 09:18:16
I have an ASP.NET MVC 4 site and I am passing a nested property to an EditorTemplate and building the field name using ViewData.ModelMetadata.PropertyName however, this gets the property name of the child property, not the full dot-notation name of the property I'm editing. An example will illustrate best: Given the following types public class EditEntityViewModel { // elided public Entity Entity { get; set} } public class Entity { // elided public string ImageUrl { get; set; } } My Edit and Create views are as follows: @model EditEntityViewModel <div> @Html.EditorFor(model => model.Entity

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;

ModelMetadata for complex type in editortemplate in asp.net mvc

强颜欢笑 提交于 2019-12-04 08:05:31
I have a viewmodel that includes a complex property of type TestThing which is declared as: public class TestThing { [Display(Name = "String3", Prompt = "String4")] public string Test1 { get; set; } [Display(Name = "String5", Prompt = "String6")] public string Test2 { get; set; } } I have an EditorTemplate for this type in which I would like to be able to access the meta data for each of the child properties. If the template was for a string for example, I could access the Prompt text by using @ViewData.ModelMetadata.Watermark , but because it is a complex type, I cannot use this method. Is

ASP.NET MVC Custom ModelMetadataProvider and ModelValidatorProvider

▼魔方 西西 提交于 2019-12-03 20:20:13
In my ASP.NET MVC application, I have metadata based model defined in database. I have a custom object defining the metadata of the data and uses dataset for DTO. To display this, I am planning to write a custom ModelMetadataProvider and ModelValidatorProvider. Is this the right approach? Any pointers on custom ModelMetadataProvider and ModelValidatorProvider? The last day or so I was trying to figure out the same. It seems that writing a custom ModelMetadataProvider and ModelValidatorProvider is the way to go if you have metadata / validation configuration stored on database, some file or