Non Action Attribute in ASP.NET WEB API

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:

  1. // GET: api/Musics  
  2.          
  3.         public IQueryable<MusicDTO> GetMusics()  
  4.         {  
  5.             return db.Musics.Include(c=> c.Composer).Select(AsMusicDto);  
  6.         }  
Response of the Action:
 
 
WEB API GET Action with Non Action Attribute: 
  1. // GET: api/Musics  
  2.      [NonAction]  
  3.       public IQueryable<MusicDTO> GetMusics()  
  4.       {  
  5.           return db.Musics.Include(c=> c.Composer).Select(AsMusicDto);  
  6.       }  
Response in POSTMAN:
 
 
 I hope you have enjoyed this blog, Thank you.