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.
- 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.
- 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.
- 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: ASP.NET MVC,ActionResult
Thanks for this.
ReplyDeleteI think #1 should be HttpNotFound.
#1 should say HttpNotFound. You need to fix that.
ReplyDeleteThis article doesn't tell me anything other than a MSDN dump.
Ahemmm - "accept the most general and return the most specific". Now be a good MVP : )
ReplyDelete(joking around)
You have HttpStatusCodeResult twice. Item one should be HttpNotFound
ReplyDeleteThanks for correction I have correct it.
ReplyDelete