I currently have this controller function:
public ViewResult Edit(int id)
{
//get user from id
var user = _adminRepository.GetUser(id);
return View(user);
}
This currently gives me an error on my view page if I attempt to edit an item with an id of 100, when there is no user with an id of 100 in the database.
What's the best practice for handling this? Send them to a Create page, or show a friendly error message? Should that redirect functionality be within the controller function?
IMO it should raise a 404 error. After all the user is requesting a resource that does not exist, much like a regular web page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With