I have an controller (Product) with several actions, some have a required parameter (Edit, Details, History) and some have a nullable parameter (Create, Search). The default route with the optional parameter will route to all of the actions, but an error will be thrown if the user enters a url pointing to a controller/action with a required parameter i.e., Product/History. What is the best place to handle this? Should I:
define routes for the actions with the required with parameter as having a required URL parameter?
routes.MapRoute( name: "ProductParamRequired", url: "Product/History/{id}", defaults: new { controller = "Product", action = "History"} );change the action to have an optional parameter and return bad request.
public ActionResult History(int? id) { if (id == null) { throw new HttpException(400, "BadRequest"); }let the application throw a 500 internal server error and show that (customized error page, of course) to the user?
Thank you and happy Friday!