I'm using MVC's DisplayFor method to show the value of a property. However, if this value is yet another Model-object, then it will include the "ID" property of that object. I don't like that, and showing the internal database ID is not nescessary in my application.
Can I (through annotations or something similar) mark this property as "not included" in the DisplayFor process?
You might not be taking advantage of what
DisplayFor
can do:and let's say that
Property
is of typeUser
Now you can create a
DisplayTemplate
(~/Views/Shared/DisplayTemplates/User.ascx) that is strongly typed toUser
and also namedUser.ascx
. And sinceProperty
is aUser
, MVC will bind thisobject
to thisUser
DisplayTemplate
.Which could look like this:
Now you can show/ hide whatever you want off of the object your passing to
DisplayFor