Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3662722
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:26:55+00:00 2026-05-19T01:26:55+00:00

Just wondering why almost every controller method I see in sample MVC code returns

  • 0

Just wondering why almost every controller method I see in sample MVC code returns ActionResult, even if it’s obvious that the code can only return one type of result. I understand there are certain instances where it’s warranted because you may return, say a RedirectResult or a ViewResult depending on the logic, but that’s not the case for most of the methods I’ve seen.

Isn’t it tantamount to having a return type of ‘object’ on a method? Why not just specify JsonResult, or FileResult or ViewResult as the return type? Is there a benefit I’m not seeing to settting the return type to ActionResult on every controller method?

Classic example:

public ActionResult Index()
{
    return View();
}

Why does this seem to be the norm instead of this:

public ViewResult Index()
{
    return View();
}

EDIT: So far all of the responses except for one have indicated that ActionResult is just more generic. I know that much. 🙂 Why is this accepted practice on a controller method though, and not anywhere else? You don’t just return the highest level-base classes of a type that you can on a normal method, you attempt to return the most specific type you can usually. What makes controller methods so different that bloggers and “sample code writers” (yes, I made that term up) would just resort to returning ActionResult?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:26:56+00:00Added an answer on May 19, 2026 at 1:26 am

    quoted verbatim from an accepted answer here on SO. makes sense to me:

    Must ASP.NET MVC Controller Methods Return ActionResult?

    You can absolutely use specific return
    types, even though most examples on
    the web seems to return the
    ActionResult. The only time I would
    return the ActionResult class is when
    different paths of the action method
    returns different subtypes.

    Steven Sanderson also recommends
    returning specific types in his book
    Pro ASP.NET MVC Framework. Take a look
    at the quote below:

    “This action method specifically
    declares that it returns an instance
    of ViewResult. It would work just the
    same if instead the method return type
    was ActionResult (the base class for
    all action results). In fact, some
    ASP.NET MVC programmers declare all
    their action methods as returning a
    nonspecific ActionResult, even if they
    know for sure that it will always
    return one particular subclass.
    However, it’s a well-established
    principle in object-oriented
    programming that methods should return
    the most specific type they can (as
    well as accepting the most general
    parameter types they can). Following
    this principle maximizes convenience
    and flexibility for code that calls
    your method, such as your unit tests.
    “

    see also:

    http://www.bengtbe.com/blog/post/2009/07/01/Use-specific-return-types-in-your-ASPNET-MVC-action-methods.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just wondering if anyone knows of a truly restful Put/delete implementation asp.net mvc preview
Just wondering if a .NET app can be compiled down to native machine code
Just wondering where is best to put functionality in an MFC application that is
Just wondering what little scripts/programs people here have written that helps one with his
Just for kind of fun I'm developing almost every algorithm (if possible) shown in
Just wondering if there is an easy way to add the functionality to duplicate
Just wondering why people like case sensitivity in a programming language? I'm not trying
Just wondering what the difference between BeginInvoke() and Invoke() are? Mainly what each one
Just wondering what the difference between MFC control messages prefixed with the following is:
Just wondering if anyone has any favourite SQL references they to use when creating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.