Questions tagged [modelmetadataprovider]

ASP.NET MVC 3 Model Metadata Providers

ASP.NET MVC 3 introduced the support for new DataAnnotation DisplayAttribute. ModelMetadataProvider can be used to create ModelMetadata based on the model’s attributes. Create a MetadataProvider to support any custom behavior.

Important Links

24 questions
1
vote
1 answer

Source Code for DataAnnotationsModelMetadataProvider

For some reason, .NET Reflector throws an exception when I try to reflect on this class. It works for everything else. What is the source code of DataAnnotationsModelMetadataProvider, please?
1
vote
2 answers

modelmetadata IsRequired not get rules validation created by FluentValidation

I have a class for create a custom validator by Fluent: public partial class RegisterValidator : BaseLarValidator { public RegisterValidator(IDbContext dbContext) { RuleFor(x =>…
1
vote
0 answers

Copy Metadata from Entities to ViewModels in Automapper 5

In my MVC application I use Autofac IoC container together with Automapper. It gives me an opportunity to implement custom ViewModels. The main question: How can I copy Metadata from Entities to ViewModels using Automapper 5.1.1? I tried to…
1
vote
2 answers

Configure Custom MetadataProvider for ViewModel

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…
Paul Taylor
  • 5,651
  • 5
  • 44
  • 68
1
vote
1 answer

Using a custom ModelMetadataProvider in a unit test

Pretty new to MVC so hopefully this is a simple question. I have written a custom binding attribute that requires access to the httpContext. In order to inject a mock httpContext during unit tests, I have written an InjectingMetadataProvider that…
1
vote
2 answers

How to add MetaData to a dynamically build MVC3 ViewModel?

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…
1
vote
1 answer

custom modelmetadataprovider for JsonResult

I wrote a custom metadata provider by inheriting it from DataAnnotationsModelMetadataProvider. The custom provider contains override implementations for GetMetadataforProperty and CreateMetadata. When I return ActionResult from my controller class…
0
votes
2 answers

In MVC 3.0 when Setting IsRequired to the ModelMetadata of a Property, it doesn't add the validation

There are certain properties in my application that I need to set dynamically whether they are required or not, therefore I can not use the [Required] atribute of Data Annotations. Maybe this is not the best way to achieve what I want. So I will…
Dzyann
  • 5,062
  • 11
  • 63
  • 95
0
votes
1 answer

How do you get the validators implementing the Fluentvalidation API in ASP.Net WebAPI

Example: public class UserValidator : AbstractValidator { public UserValidator() { RuleFor(p => p.Username).NotEmpty() .WithMessage("Please enter a username."); } } public class UserController :…
1
2