eWorld.UI - Matt Hawley

Ramblings of Matt

ASP.NET MVC - ActionResult... The Good & Not So Bad

April 18, 2008 18:21 by matthaw

I'm thoroughly enjoying the new ActionResult feature the ASP.NET team introduced into the "refresh" of the Preview 2 bits... or whatever they're calling it now :) Introducing this has increased productivity regarding testing the results of a controller's action. Here's a quick summary of the different types:

  • RenderViewResult - this result is returned when you call RenderView on the controller. It has properties like ViewName, MasterName, ViewEngine, ViewData, and TempData.
  • ActionRedirectResult - this result is returned when you call RedirectToAction on the controller. It exposes a dictionary of information.
  • HttpRedirectResult - this result is returned when you call Redirect. It exposes the Url that it is to redirect to.
  • EmptyResult - This is used for any other purpose in which you don't want the controller to complete the execution on. I have already used this for outputting HTML to the response stream for a specific purpose.

Now that these action results are present, there's no need to have your own view engine that captures the same information. What else is great, is that you can implement your own action result to do whatever you wish!

Onto the Not so Bad

1. When calling RenderView with the parameterless method, this renders testability useless because the RenderViewResult that is returned has Null values where you'd expect to find a value. For example, the critical property "ViewName" is null.

2. I feel that ActionRedirectResult should expose a ViewName and ViewData property. As it stands, when you call RedirectToAction, it takes your view name you've specified and puts it within the RouteValueDictionary it exposes. While this is still testable - it would be much easier to test if I could just go off of ViewName and ViewData.

All in all, this is a very good start to using ActionResults, and I love using them. Hope my insight helps!

kick it on DotNetKicks.com


Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Comments

April 19. 2008 23:56

Pingback from weblogs.asp.net

ASP.NET MVC - ActionResult... The Good & Not So Bad - eWorld.UI - Matt Hawley

weblogs.asp.net

April 20. 2008 01:10

Hi Matt, thanks for pointing out the EmptyResult return value, I had not yet discovered that and was coincidentally trying to figure out how to do just that when I ran across this post. One annoyance with it is that you can't just say "return EmptyResult();" like the others; you have to say "return new EmptyResult();". An "EmptyResult" method on the Controller class would be nice to keep it more in line with the other default ActionResults.

Troy Goode

April 20. 2008 01:12

Also, I hope they modify the ComponentController to use ActionResult goodness as well. =)

Troy Goode

May 8. 2008 10:59

Pingback from hsidev.wordpress.com

ASP.NET MVC Resources « HSI Developer Blog

hsidev.wordpress.com

March 21. 2009 10:18

Nice short but very clear post

Bayram Çelik

July 18. 2009 11:49

Thank you for useful information was a good article

sex movies

August 2. 2009 00:59

hi all.
thank too the apple. http://www.germanporn.tk

Porno filme

August 2. 2009 01:00

Thanks a lot for this scripot.I have been looking for it for a long time http://www.tvsexizle.com

Porno izle

August 8. 2009 01:40

Can anyone suggest me one good book to learn spring mvc in J2EE?

seo

August 9. 2009 03:08

The site was very informative however it didn't have the information I was looking for.

tiffany

August 18. 2009 00:26

Can u compare jsp and asp.net over security issues, fastness, cost effective? Which is best to avoid hacking?

Internet marketing

September 5. 2009 18:18

The site was very informative however it didn't have the information I was looking for.

best trading forex system

September 5. 2009 18:18

Can anyone suggest me one good book to learn spring mvc in J2EE?

forex trading systems that work

September 9. 2009 20:00

good

tiffany

September 14. 2009 06:09

very very thanks

Free Forex

September 23. 2009 23:25

Where can I get the details on these results.

Tim

October 7. 2009 06:51

i want to see the ending result. I have been having problems with this for while. Thanks for the great info.

Adapter

October 8. 2009 04:40

4RX is an online pharmacy to Buy Viagra online. Buy cheap generic drugs like Sildenafil (GENERIC VIAGRA) online and Generic Levitra Online.

Buy Viagra

October 10. 2009 22:28

great post

tag heuer watches

October 15. 2009 09:58

great post!
informative and interesting!
thanks for sharing!

http://www.seattlecarpetcleaning.com
www.heavensbest.com/.../rug-cleaning.html

peter north

October 15. 2009 17:46

Here the description for asp.net leaners.
This is very simple site.
lookly good.

<h1><b><a href="http://www.onlinemovieguru.com">watch free movies</a>

cyber

October 16. 2009 20:18

Thank you for useful information was a good article

free online games

October 19. 2009 07:54

Hi nice site design


Regards

frio

buy aion online accounts

October 20. 2009 12:26

Thanks for the very informative post. It's good someone takes real interests in these things and shares them us.

Apex Professionals LLC

October 21. 2009 01:36

GOOD JOB,I like it!

ed hardy

October 21. 2009 02:40

One of the best posts I have come across this week, thank you and keep more of this kind coming, i will be here again.

Debra

Medela Symphony

October 21. 2009 03:12

Can u compare jsp and asp.net over security issues, fastness, cost effective? Which is best to avoid hacking?

toshiba laptops

October 21. 2009 05:51

Is it necessary to know all the languages to make multilingual website in asp.net?

Income protection insurance

October 21. 2009 13:11

Another cool post, you are simply outstanding.

underground electric dog fence

Comments are closed

Copyright © 2000 - 2010 , Excentrics World