I have the following MVC Action:
[ActionName("order-brochure")]
public ActionResult OrderBrochure(int brochureId, bool isModal = true)
{
return View(HomeModelBuilder.BuildOrderBrochureModel(brochureId, isModal, false));
}
Where isModal is an optional parameter
Is there any other way to set the default for this other than using bool isModal = true within the method as my company uses code analysis and this fails giving a CA1026: default parameters shouldn't be used
However, I can't override the method as you can't have two actions with the same name as you'll get an error along the following lines:
The current request for action 'order-brochure' on controller type 'HomeController' is ambiguous between the following action methods:
System.Web.Mvc.ActionResult OrderBrochureModal(Int32, Boolean) on type MarshallsCoUkCommercial.Website.Controllers.HomeController
System.Web.Mvc.ActionResult OrderBrochure(Int32) on type MarshallsCoUkCommercial.Website.Controllers.HomeController
And if I use
public ActionResult OrderBrochure(int brochureId, bool isModal)
Setting isModal to UrlParameter.Optional
I can't test to see if isModal is null as it will always be set to false
public ActionResult OrderBrochure(int brochureId, bool? isModal)? Now you can test it to see if it'snull.