I have the following routes in my controller. One Get and two post actions. All have the same action name. The two post actions are differentiated using the MultipleButton attribute as explained here:
[RoutePrefix("incidents")]
public sealed class IncidentsController : Controller
{
[HttpGet, Route("action/{id:int?}/{error?}")]
public async Task<ActionResult> Action(int? id, string error = null)
[HttpPost, Route("action"), ActionName("Action"), ValidateAntiForgeryToken]
[MultipleButton(Name = "action", Argument = "Accept")]
public async Task<ActionResult> ActionAccept(IncidentActionViewModel incident)
[HttpPost, Route("action"), ActionName("Action"), ValidateAntiForgeryToken]
[MultipleButton(Name = "action", Argument = "Reject")]
public async Task<ActionResult> ActionReject(IncidentActionViewModel incident)
}
@Url.Action("Action", "Incidents", new { id = 10 })
The above route gets rendered as shown below. Navigating to this URL works but if I change the 'id' parameter from Nullable to int I start to get errors.
/incidents/action?id=10
It should be rendering as shown below and I should not get errors if I change the 'id' parameter to type int:
/incidents/action/10
What am I doing wrong?
UPDATE
Here are my route registration details:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });