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?
nullin your example) should not throw an exception at all, because it is a Client issue, not a server one.BadRequest(400) is exactly the status code for this kind of issues (signaling a client that it has sent an invalid request).