Questions tagged [modelmetadata]
88 questions
                    
                    25
                    
            votes
                
                5 answers
            
        Is it possible to override the required attribute on a property in a model?
I'm curious to find out if it is possible to override the [Required] attribute that has been set on a model. I'm sure there most be a simple solution to this problem, any takers?
        
        Ryan Smith
        
- 475
 - 1
 - 8
 - 19
 
                    18
                    
            votes
                
                6 answers
            
        ASP.NET MVC 3 HtmlHelper Exception does not recognize ModelMetadata on inherited interface
After upgrading to MVC 3 RTM I get an exception where it previously worked.
Here is the scenario. I have several objects that use the same underlying interfaces IActivity and IOwned. 
IActivity implements IOwned (another interface)
public interface…
        
        Dax70
        
- 1,051
 - 1
 - 8
 - 16
 
                    16
                    
            votes
                
                3 answers
            
        Technique for carrying metadata to View Models with AutoMapper
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…
        
        smartcaveman
        
- 41,281
 - 29
 - 127
 - 212
 
                    11
                    
            votes
                
                2 answers
            
        Custom Html helper that can browse DataAnnotations
Say I have a model like this
public class User
{
    [Required]
    [StringLength(14, ErrorMessage = "Can only be 14 characters long")]
    public string UserName;
}
I want to create a Html helper like this:
@Html.ValidatableEditorFor(m =>…
        
        Chris
        
- 7,996
 - 11
 - 66
 - 98
 
                    8
                    
            votes
                
                3 answers
            
        Entity Framework - Get Table name from the Entity
I'm using the Entity Framework 4.1 with Code First approach. I'm able to get the storage model types and column names of my entities:
var items = context.ObjectContext.MetadataWorkspace.GetItems(DataSpace.SSpace);
foreach (var i in… 
        
        0xbadf00d
        
- 17,405
 - 15
 - 67
 - 107
 
                    7
                    
            votes
                
                3 answers
            
        ASP.NET MVC ModelMetadata - Do we violate separation of concerns when we put attributes to describe UI on model?
According to this blog post  "ModelMetadata objects are constructed with data taken from attributes, primarily from the System.ComponentModel and System.ComponentModel.DataAnnotations namespaces."  
By putting UI helper attributes on Model objects…
        
        dev.e.loper
        
- 35,446
 - 76
 - 161
 - 247
 
                    7
                    
            votes
                
                1 answer
            
        expression.Compile() vs ModelMetadata.FromLambdaExpression
There is a common issue to write strongly-typed Html helpers.
The problem is how to retrieve property name/value pair.
Assume we have following Html helper declaration:
public static string DatePickerFor(this HtmlHelper helper,…  
        
        Cheburek
        
- 2,103
 - 21
 - 32
 
                    7
                    
            votes
                
                2 answers
            
        Can I use an IMetadataAware attribute multiple times on the same field?
I have fields that different people should see in different names. 
For example, suppose I have the following user types:
public enum UserType {Expert, Normal, Guest}
I implemented an IMetadataAware…
        
        Kobi
        
- 135,331
 - 41
 - 252
 - 292
 
                    6
                    
            votes
                
                2 answers
            
        MVC HtmlHelper vs FluentValidation 3.1: Troubles getting ModelMetadata IsRequired
I created a HtmlHelper for Label that puts a star after the name of that Label if associated field is required:
public static MvcHtmlString LabelForR(
        this HtmlHelper html, Expression>…   
        
        Dmitry Efimenko
        
- 10,973
 - 7
 - 62
 - 79
 
                    6
                    
            votes
                
                2 answers
            
        ModelMetaData, Custom Class Attributes and an indescribable question
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…
        
        Doug Chamberlain
        
- 11,192
 - 9
 - 51
 - 91
 
                    6
                    
            votes
                
                5 answers
            
        MVC2 - How to obtain parent model (container) inside template
I'm writing an MVC2 app using DataAnnotations. I have a following Model:
public class FooModel 
{
    [ScaffoldColumn("false")]
    public long FooId { get; set; }
    [UIHint("BarTemplate")]
    public DateTime? Bar { get; set;}
}
I want to…
        
        Jakub Konecki
        
- 45,581
 - 7
 - 87
 - 126
 
                    5
                    
            votes
                
                0 answers
            
        Is there a way to effectively make [ModelMetadataType] work across multiple assemblies?
I have an ASP.NET Core 3.1 web API application that has various models used for by its endpoints for input and output of data. Because other C# applications will be communicating with this one, I decided to move these shared models to a NuGet…
        
        Ian Kemp
        
- 28,293
 - 19
 - 112
 - 138
 
                    5
                    
            votes
                
                2 answers
            
        ModelMetadata for complex type in editortemplate in asp.net mvc
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 =…
        
        Paul Hiles
        
- 9,558
 - 7
 - 51
 - 76
 
                    5
                    
            votes
                
                2 answers
            
        Get ModelMetadata for a class in .NET Core
In Entity Framework 6 I could get the ModelMetadata for a class (myModel) like this:
var modelMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, myModel.GetType());
How can I do the same in .net core 1.1.1?
        
        simon of earth
        
- 119
 - 1
 - 6
 
                    5
                    
            votes
                
                3 answers
            
        MetadataType and client validation in ASP.NET MVC 2
Inherited properties and MetadataType does not seem to work with client side validation in ASP.NET MVC 2.
The validation of our MetadataTypes work as expected on the server but for some reason it does not generate the appropriate client scripts for…
        
        Kristoffer Ahl
        
- 1,661
 - 2
 - 18
 - 36