asp.net-mvc


PCL Attribute not seen in MVC ModelMetaDataProvider


I have a small PCL attribute to display a string for enum values:
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public sealed class EnumDescriptionAttribute : Attribute
{
private readonly string description;
public EnumDescriptionAttribute(string description)
{
this.description = description;
}
public string Description { get { return description; } }
}
I have made a CustomMetadataProvider for my MVC Project like that:
public class CustomMetadatprovider : DataAnnotationsModelMetadataProvider
{
protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName)
{
var modelMetadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
if (attributes.OfType<EnumDescriptionAttribute>().Any())
{
modelMetadata.DisplayName = attributes.OfType<EnumDescriptionAttribute>().First().Description;
}
return modelMetadata;
}
}
The enum where I apply the attribute on:
public enum RequestStatus
{
[EnumDescription("Unknown value")]
Unknown = 0,
[EnumDescription("New value")]
New = 10,
[EnumDescription("In Progress value")]
InProgress = 20,
[EnumDescription("Terminated value")]
Terminated = 30,
[EnumDescription("Canceled value")]
Cancelled = 40
}
In my startup.cs:
ModelMetadataProviders.Current = new CustomMetadatprovider();
I go through the my custom metada provider but my attribute is never listed on the field.
Am I missing Something?
EDIT
I made some progress, the attribute is seen if I apply it to the ViewModel like this:
public class RequestViewModel
{
public Guid Id { get; set; }
[EnumDescription("Provider are you seeing me?")]
public RequestStatus Status { get; set; }
public string Note { get; set; }
}
The metadataprovider is not seeing the EnumDescriptionAttribute on Status value
public class RequestViewModel
{
public Guid Id { get; set; }
public RequestStatus Status { get; set; }
public string Note { get; set; }
}

Related Links

When I update ASP.NET MVC from 5.0 to 5.1, do I need to update the bindingRedirect to 5.1?
Set ClaimsAuthorizationManager in Code (MVC 5)
KendoUi MVC Grid passing parameter values
How exactly does CSS/Javascript minification and bundling work in MVC?
Roles Comparison in MVC
Route Id overrides Model.Id
View containing paging and Multiple Models
Asp.net Mvc Setting an attribute of any model which contains
WebApi (ApiController) vs OData (ODataController) in ASP.Net MVC
MVC architecture large action method on controller
Using .NET MVC/WebAPI, Is it possible to share an auth cookie between two projects of the same solution? If so, how?
Is it possible to send content body with get request in c# using HTTP 1.1
ASP.NET MVC Using DropDownLists
Mapping User.Identity in .NET MVC app to active directory user
MVC 4 External link
Orchard Projections & Collapse Accordion

Categories

HOME
odoo-10
vb.net
selenium
actions-on-google
angular2-forms
jsessionid
fonts
bootstrap-selectpicker
image-segmentation
gluu
jqgrid
xcode8
addeventlistener
mvvm-light
build.gradle
sql-server-express
command-line-interface
jsqmessagesviewcontroller
spring-boot-admin
pywin32
teamcity-9.0
sfsafariviewcontroller
nested-set-model
amazon-cloudfront
liferay-aui
epicorerp
apache-httpcomponents
vnc
listbox
android-arrayadapter
webfocus
arduino-esp8266
apscheduler
monads
angular2-databinding
charts.js
pdfstamper
draggable
disqus
internet-explorer-10
angular2-seed
freecodecamp
kendo-chart
hostapd
openwebanalytics
manifoldjs
asyncsocket
notimplementedexception
stroke
canopen
infiniband
kony
abbyy
maven-versions-plugin
cmsmadesimple
haste
gpt
kie-workbench
lapply
agile-processes
topojson
hapi.js
coldfusion-11
data-fitting
menustrip
benerator
selenium2library
bash-completion
uiswitch
facebook-comments
asp.net-authorization
linqtocsv
ane
python-2.3
many-to-one
pyenchant
wt
perfview
translate3d
spatial-index
pencilblue
fastparse
gitattributes
twitter-follow
mklink
asf
before-save
nitrogen
cellular-automata
mydbr
xsltforms
requiredfieldvalidator
preon
sysadmin
pligg
mips64
tempo
domain-mapping
rc-shell
guvnor
google-website-optimizer
xml-dtd
undeclared-identifier
nsinvocation
azure-role-environment
livevalidation
blackberry-jde
openfeint
sharepoint-timer-job
msn-messenger
project-settings
usenet
graceful-degradation

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App