Thursday, July 7, 2011

Redirecting to Different Controllers in ASP.NET MVC

Last year, we started using ASP.NET MVC at work and are still learning its intricacies. About a month ago, I needed to put in a button that redirected to another part of the application. I have sanitized the details because they aren't germane. The button was located on a page controlled by a different controller than the page I wanted to redirect to. I tried the following 3 incorrect snippets before seeing the error, which is corrected in the last snippet.

<HttpPost()> _
<ActionName("Index")> _
<HandlesButton("redirectingaction")> _
Public Sub RedirectToOtherController()
  Redirect("OtherController.ashx/NewAction")
End Sub
<HttpPost()> _
<ActionName("Index")> _
<HandlesButton("redirectingaction")> _
Public Sub RedirectToOtherController()
  Redirect("~/OtherController.ashx/NewAction")
End Sub
<HttpPost()> _
<ActionName("Index")> _
<HandlesButton("redirectingaction")> _
Public Sub RedirectToOtherController()
  RedirectToAction("NewAction", "OtherController")
End Sub

Can you spot the difference? Some of our MVC actions perform operations on the server with no need for a return value. But the redirect needs a return value to switch views. So I needed to have a function with a return statement.

<HttpPost()> _
<ActionName("Index")> _
<HandlesButton("redirectingaction")> _
Public Function RedirectToOtherController() As ActionResult
  Return RedirectToAction("NewAction", "OtherController")
End Function

Seagate FreeAgent Error 2013

I have a Seagate FreeAgent external drive to help with backups.

About 2 weeks ago, the nightly backup started failing. It was always one particular file that couldn't get copied and the error code was 2013.

A number of sites from the Google indicated that it was a file permission issue on both the backup drive and the source drive. I made sure that the file was not marked as read-only, but the backup still kept failing.

I finally stumbled upon this post from the Seagate website itself.

Per the article, I deleted the offending file from the backup drive and restarted the backup. It is now working again.