DisplayFor vs PropertyFor vs EditAttribute

Vote:
 

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?

#249165
Feb 24, 2021 17:49
Vote:
 

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

For PropertyFor Vs EditAttribute please check the following thread

https://world.episerver.com/forum/legacy-forums/Episerver-7-CMS/Thread-Container/2013/3/PropertyFor-vs-EditAttributes/#67856

#249172
Feb 24, 2021 21:58
Vote:
 

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!

 

#249204
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.