In ASP.Net MVC if I have a method on a controller that returns a View should that method be of type ViewResult or the more general ActionResult?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A similar question was asked on the ASP.NET forums: http://forums.asp.net/t/1423519.aspx
Basically, it comes down to style — in OOP, you try to return the most specific type that you can given the situation. You don’t return
objectfor every method that you have — sometimes you returnstring, sometimesList, sometimes a custom class.In the forum replies, someone quotes Stephen Walther from his book:
So using the more specific
ViewResultwould be preferred, especially from a unit testing perspective.