Spot the bug #2
I came across this issue just at quitting time yesterday and was blown away when I realized what was happening.
The UsersController Index View (pre submit)
The UsersController Code
Back
The UsersController Code
public class UsersController : Controller
{
List<string> users = new List<string> ()
{
"mace.windu",
"yoda",
"senator.amidala",
"anakin.skywalker",
"obiwan.kenobi"
};
public ActionResult Index()
{
return View( users );
}
[HttpPost]
public ActionResult Delete ( string[] userstodelete )
{
if ( userstodelete == null || userstodelete.Length == 0 )
{
throw new ArgumentException (
"argument must contain at least one entry",
"userstodelete" );
}
// code could go here to
// call out to some service to
// delete these users
TempData["deletedUsers"] = userstodelete;
foreach ( var user in userstodelete )
users.Remove ( user );
return View ("Index", users);
}
}
Problem
Looks like it should all work perfectly right? That's what I thought. However, clicking "Delete Users" will only "delete" our pre-darth user "anakin.skywalker".
Why?
Hint: Everything here is working exactly as it should.
Let's talk about this