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

  • SEARCH
  • Home
  • 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 1071427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:42:49+00:00 2026-05-16T20:42:49+00:00

In ASP.Net MVC if I have a method on a controller that returns a

  • 0

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?

  • 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-16T20:42:49+00:00Added an answer on May 16, 2026 at 8:42 pm

    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 object for every method that you have — sometimes you return string, sometimes List, sometimes a custom class.

    In the forum replies, someone quotes Stephen Walther from his book:

    NOTE 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.

    So using the more specific ViewResult would be preferred, especially from a unit testing perspective.

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

Sidebar

Related Questions

I have an ASP.NET MVC project with a form. In the Action method that
In my asp.net-mvc website I have a field that usually has a string (from
Assume I have an ASP.NET MVC app that's not doing anything too fancy (no
Does ASP.NET MVC have anything like the RESTful out-of-the-box features like Ruby on Rails
ASP.NET MVC routes have names when mapped: routes.MapRoute( Debug, // Route name -- how
Have just started playing with ASP.NET MVC and have stumbled over the following situation.
I am in the start up of a project using ASP.NET MVC and have
I am currently creating an e-commerce site using C# ASP.NET MVC and have just
Although ASP.NET MVC seems to have all the hype these days, WebForms are still
I'm trying out ASP.NET MVC routing and have of course stumbled across a problem.

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.