Monday, March 28, 2011

Three new Action Result Type in ASP.NET MVC 3

In ASP.NET MVC incoming browser request mapped to a controller’s action method and that action method returns type of ActionResult in response to the browsers request. I was playing bit with ASP.NET MVC3 to check out new features of ASP.NET MVC 3 and I have found three great new ActionResult Type. Below is details explanation of each one.

  1. HttpNotFound: This return type returns a error 404 on client. This action result type can be very useful when we have resources that are not found and so we can notify the client with 404 error.
  2. RedirectResult:This returns a temporary redirect code 302 or permanent redirect code 302 depending upon a Boolean flag. This kind of redirection is very important for Search Engine optimization. I have already discussed this feature with asp.net 4.0 here.
  3. HttpStatusCodeResult: Returns a user specified code so developer have choice to return specific error code.

Here are code example of Action ResultType how we can use that in code.

public ActionResult SpecificResult()
{
return new HttpStatusCodeResult(404);
}

public ActionResult NotFound()
{
return HttpNotFound();
}

public ActionResult PermanentRedidrect()
{
return new RedirectResult("http://jalpesh.blogspot.com");
}
Hope you liked it.. Stat tuned for more..Happy Programming
Technorati Tags: ,
Shout it
kick it on DotNetKicks.com
Share:

5 comments:

  1. Thanks for this.
    I think #1 should be HttpNotFound.

    ReplyDelete
  2. #1 should say HttpNotFound. You need to fix that.

    This article doesn't tell me anything other than a MSDN dump.

    ReplyDelete
  3. Ahemmm - "accept the most general and return the most specific". Now be a good MVP : )
    (joking around)

    ReplyDelete
  4. You have HttpStatusCodeResult twice. Item one should be HttpNotFound

    ReplyDelete

Your feedback is very important to me. Please provide your feedback via putting comments.

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews