Try our conversational search powered by Generative AI!

DisplayFor vs PropertyFor vs EditAttribute


Could someone please tell me when to use DisplayFor, PropertyFor, EditAttribute also which one is best to use?

also, what is the difference between them?

Feb 24, 2021 17:49

The DisplayFor helper renders the corresponding display template for the given type.

For PropertyFor Vs EditAttribute please check the following thread

Feb 24, 2021 21:58

DisplayFor is the .NET standard way. It will render your property alright but it won't have any on-page editing. You can create your own display templates for different property types if you wish just like for a normal .NET MVC project. Not commonly used for Episerver properties because of the limitations to editor support.

PropertyFor is the recommended Episerver way of rendering a property. It's a DisplayFor with superpowers basically. You should use this one to get editor support for your properties with the minimal amount of code. 

Edit Attribute can be helpful sometimes if you want editor support for your property but the PropertyFor doesn't render the thing with the exact html you want. So use this one instead of PropertyFor if you want detailed control of the rendering and still need editor support. 

Happy coding!


Feb 25, 2021 9:15
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.