Hello readers In this tutorial we are going to see what is the difference between ViewResult() and ActionResult() in ASP.NET MVC. This is a very interesting topic for interview point of view.

Difference between ViewResult() and ActionResult() in ASP.NET MVC:

 

 

 

View Result

ActionResult

1-ViewResult can return only view result type.Action Result can return many types of results like PartialViewResult, JSONResult.
2-ViewResult class is derived from the base class ActionResult.ActionResult is a base class for ViewResult.
3-It is a concrete class.It is an abstract class.
4-It is a concrete class so no subtypes available.

ActionResult has many subtypes available:

  • ViewResult – Renders a specified view to the response stream.
  • PartialViewResult – Renders a specified partial view to the response stream.
  • EmptyResult – An empty response is returned.
  • RedirectResult – Performs an HTTP redirection to a specified URL.
  • RedirectToRouteResult – Performs an HTTP redirection to a URL that is determined by the routing engine, based on given route data.
  • JsonResult – Serializes a given object to JSON format.
  • JavaScriptResult – Returns a piece of JavaScript code that can be executed on the client.
  • ContentResult – Writes content to the response stream without requiring a view.
  • FileContentResult – Returns a file to the client.
  • FileStreamResult – Returns a file to the client, which is provided by a Stream.
  • FilePathResult – Returns a file to the client.
5-

If we are sure that our action method will return the only view we can go with ViewResult.

For Example:
public ViewResult Index()
{
return View(); // this is a view result class
}

If our action method may return view or redirect to some URL we should go with ActionResult.

For Example:

public ActionResult DynamicView(bool IsHtmlView)
{
if (IsHtmlView)
return View(); // returns simple ViewResult
else
return Json(); // returns JsonResult view
}

View More:

Conclusion:

I hope you understand the Difference between VieweResult() and ActionResult() in ASP.NET MVC. Your Feedback and comments are welcome to me.

Thank You,

31 Comments

  • whoah this blog is excellent i like studying your posts. Keep up the good work!

    You realize, many people are searching around for this information, you can aid
    them greatly.

  • I’ve been exploring for a little for any high-quality articles or weblog posts in this sort
    of house . Exploring in Yahoo I at last stumbled upon this site.

    Studying this information So i am satisfied to convey that I’ve a
    very just right uncanny feeling I came upon exactly what I needed.
    I such a lot for sure will make sure to do not omit this site and provides it a glance on a constant basis.

  • Wow that was unusual. I just wrote an very long comment but after I clicked submit
    my comment didn’t appear. Grrrr… well I’m not writing all that over again. Anyhow, just wanted to say wonderful
    blog!

  • Why users still use to read news papers when in this technological globe everything is existing on net?

  • Admiring the time and effort you put into your website and in depth information you offer.
    It’s nice to come across a blog every once in a while that isn’t the same unwanted rehashed material.
    Wonderful read! I’ve bookmarked your site and I’m adding your RSS feeds to my
    Google account.

  • If you want to increase your know-how simply keep visiting this site and be updated with the most up-to-date news update posted here.

  • Thank you, I have just been looking for information about this subject for a while and yours
    is the best I’ve discovered so far. But, what in regards to the bottom line?
    Are you certain concerning the supply?

  • Have you ever thought about creating an ebook
    or guest authoring on other websites? I have a blog based
    upon on the same ideas you discuss and would really like to
    have you share some stories/information. I know my audience would appreciate your work.
    If you’re even remotely interested, feel free to send me an email.

  • When I initially commented I clicked the “Notify me when new comments are added” checkbox and
    now each time a comment is added I get several e-mails with the same
    comment. Is there any way you can remove people from that service?
    Thanks!

  • I was very pleased to uncover this website.
    I need to to thank you for your time for this particularly fantastic read!!

    I definitely appreciated every bit of it and
    I have you book marked to see new stuff on your site.

  • Wow that was odd. I just wrote an really long comment but after I clicked submit my comment didn’t
    appear. Grrrr… well I’m not writing all that over again. Regardless, just wanted to say wonderful blog!

  • Howdy! Would you mind if I share your blog with my facebook group?
    There’s a lot of folks that I think would really enjoy your content.
    Please let me know. Many thanks

  • Hey there superb website! Does running a blog similar to this require a great
    deal of work? I have no knowledge of programming however I was hoping to start my own blog
    in the near future. Anyways, if you have any recommendations or tips for
    new blog owners please share. I know this is off topic nevertheless I simply wanted to ask.
    Thanks!

  • Hello! Someone in my Myspace group shared this website with
    us so I came to give it a look. I’m definitely loving the information.
    I’m bookmarking and will be tweeting this to my followers!
    Excellent blog and excellent style and design.

  • I’ve learn some excellent stuff here. Definitely value bookmarking for
    revisiting. I wonder how much effort you put to make this sort of great informative web
    site.

  • Great blog! Is your theme custom made or did you download
    it from somewhere? A design like yours with a few simple tweeks would really make my blog jump out.

    Please let me know where you got your design. Thank you

  • Howdy, i read your blog occasionally and i own a similar one and
    i was just curious if you get a lot of spam responses?
    If so how do you stop it, any plugin or anything you can recommend?
    I get so much lately it’s driving me insane so any support is very much appreciated.

  • It’s a shame you don’t have a donate button! I’d without a doubt donate to
    this brilliant blog! I suppose for now i’ll settle for book-marking and adding your RSS feed to my Google account.
    I look forward to brand new updates and will talk about this site with my Facebook group.
    Chat soon!