Approaches to handle ../Dinners/Details

Apr 2, 2009 at 6:22 PM
Edited Apr 2, 2009 at 6:31 PM
Using a URL like http://localhost:1368/Dinners/Details results in a "null entry for parameter 'id' of non-nullable type" exception. What are the common approaches that provide a friendly user experience to handle this case? Ideas that come to mind:

* Make the id parm of the action method optional and check it, though I'm not certain that's doable. Return the "NotFound" view. Or redirect to the Dinners list.

* Implement an attribute on the id parm to provide a default as described at http://www.coderjournal.com/2008/08/parameter-attribute-default-value-mvc-action-method/; A default of 1 would return the dinner row of id of 1, if it exists, or would return the "NotFound" view.

Any other approaches that would be considered a good user experience?

[Update]: After posting, I did change Global.asax.cs to use id = "1" in the parameter defaults which worked fine (and appears counter to the behavior described in the coderjournal link in bullet 2). But I'd still be interested in hearing alternative behavior approaches.
Apr 6, 2009 at 4:15 PM
The approach you did makes sense. Or make the id a nullable integer. That allows doing your first bullet point.