The NonAction attribute is used to prevent a method from getting invoked as an action. This attribute tells to the framework that the method is not an action, inspite of it will match with routing rules or not.
WEB API GET Action:
- // GET: api/Musics
- public IQueryable<MusicDTO> GetMusics()
- {
- return db.Musics.Include(c=> c.Composer).Select(AsMusicDto);
- }
Response of the Action:
WEB API GET Action with Non Action Attribute:
- // GET: api/Musics
- [NonAction]
- public IQueryable<MusicDTO> GetMusics()
- {
- return db.Musics.Include(c=> c.Composer).Select(AsMusicDto);
- }
I hope you have enjoyed this blog, Thank you.

Anindya SarkarPosted Jul 4, 2021, 4:58 PM
Hello Gowtham, if we make any action method in controller as private it will behave exactly same way .