Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return types in ASP.NET MVC Actions

Is it recommended to define specific return types for controller actions?

Or in other words since results like JSONRESULT, VIEWRESULT etc... derive from ACTIONRESULT what is the best practice in terms of specifying the return type for a controller action.

ACTIONRESULT or a more specific Result type.

Is there any best practice/OOAD aspect approach to this.

like image 858
ckv Avatar asked Oct 04 '22 19:10

ckv


2 Answers

I don't think there is a specific recommendation for that. My opinion today (I used to be more specific) is the same as Dan, because I find it easier to maintain my code that way.

like image 195
gsimoes Avatar answered Oct 07 '22 18:10

gsimoes


The best practise is always that to keep our method's parameters and return types the most generic types like we accept IEnumerable not an T[] and this is true for return types.

like image 35
Peter Kiss Avatar answered Oct 07 '22 19:10

Peter Kiss