Bonjour à tous,
J’ai généré un bug en faisant ceci :
Afficher le détail d’un article avec dont l’identifiant est 1 voir lien
http://localhost:1234/Contenu/Articles/Details/1
Puis remplacer son numéro par 5 qui ne correspond à l’identifiant d’un article, voir lien
http://localhost:1234/Contenu/Articles/Details/5

ET çà donne :

Sequence contains no elements

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Sequence contains no elements

Source Error:

[No relevant source lines]
PAR ANALOGIE :

Server Error in '/' Application.
Sequence contains no elements

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Sequence contains no elements

Source Error:

Line 126: CurrentPage(page);
Line 127: ViewData["State"] = state;
Line 128: OpenCategoryId(id);
Line 129: return View(db.Categories.Single(c => c.Id == id));
Line 130: }

Source File: C:\Intranet 30 fev\Intranet\Areas\Contenu\Controllers\ArticlesController.cs Line: 0
Comment faire pour que même si on saisie dans l’URL un numéro ne correspondant pas à l’identifiant d’un élément dans la base çà n’affiche pas une telle erreur ?
Merci.