Best practice for trying to edit an item that does not exist?

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 browse page if I try to edit an item with id 100 if there is no user with id 100 in the database.

What is the best practice for this? Send them to the "Create" page or show a friendly error message? Should this redirection function be in the controller function?

+5
source share
4 answers

, , " ", .

, , " ", " " ( , ) .

+5

IMO 404. , , , -.

+6

, " " , .

+1

@RPM1984, , , . , : ", , ". "", , . , .

, URL , .

.

http://mysite.com/users/edit/215215132

215215132 - userId.

, .

+1

All Articles