In ASP.NET MVC apps, when we scaffold the controllers in Visual Studio, we get the default actions:
- Index
- Create
- Delete
- Edit
- Details
Of the above, a few have a nullable id (int? id) for parameters: Details, Edit (GET version), Delete, DeleteConfirmed. Then in at least some, there's the following code to ensure that ID isn't null:
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
All these actions require an ID; it's not optional. You can't display the details of nothing or delete nothing, etc. Also, we're then generating a BadRequest status code if they're null.
So why aren't these parameters non-nullable integers to begin with?