Мы делаем это как так; этот код найден в BaseController
/// <summary>
/// returns our standard page not found view
/// </summary>
protected ViewResult PageNotFound()
{
Response.StatusCode = 404;
return View("PageNotFound");
}
названным как так
public ActionResult ShowUserDetails(int? id)
{
// make sure we have a valid ID
if (!id.HasValue) return PageNotFound();
Here is a couple of answers:
Edit: The 3rd answer has been updated with the input provided by Nick Johnson in a comment.