Filed under: Software Development

Simple MVC Redirect after Action Completion

I ran across a rather simple problem today that I did not find a lot of simple documentation to explain so here is my simple example to hopefully help whoever might stumble upon this same question.

The Scenario:

I have a simple controller that posts data to an API, at the conclusion it hands back the newly inserted item so I can display it to my user.  However the action to add the item is not the same action that displays the newly inserted item.  The problem is how do I hand off the newly inserted item to the other action handler.

The Solution:

Pretty simple in the long run using the “RedirectToAction” method.  In the end it looks a lot like this:

return RedirectToAction("Get", new RouteValueDictionary() { { "id", response.Id } });

I simply tell the method where to go and create a simple value dictionary object with my single Guid to pass on and lookup the object.  All in all pretty simple and you can even build up the dictionary to add other objects if you needed to.

Brent

Successful Programming

I came across this list a professor with the University of Phoenix posted.  Pretty cool little test for any software firm.

Recently I have become a fan of Joel Spolsky, who worked at Microsoft for several years and has created a large collection of articles and thoughts about Best Software Practices, as well as the process of programming and design.  In one of his articles, he mentions the Joel Test: 12 Steps to Better Code:

  1. Do you use source control?
  2. Can you make a build in one step?
  3. Do you make daily builds?
  4. Do you have a bug database?
  5. Do you fix bugs before writing new code?
  6. Do you have an up-to-date schedule?
  7. Do you have a spec?
  8. Do programmers have quite working conditions?
  9. Do you use the best tools money can buy?
  10. Do you have testers?
  11. Do new candidates write code during their interview?
  12. Do you do hallway usability testing?

For each correct answer you get one point, most software companies, and development groups score between 2-4. His claim was that Microsoft's score was in the 10-12 range, and that it was one of the reasons MS is successful.

-Brent

del.icio.us Tags: