I have applied a route attribute at the controller level, but I want to exclude an action from being routed. Not overriding but excluding the route completely. How can this be achieved?
Let's say I have:
[RoutePrefix("promotions")]
[Route("{action=index}")]
public class ReviewsController : Controller
{
// eg.: /promotions
public ActionResult Index() { ... }
// eg.: /promotions/archive
public ActionResult Archive() { ... }
// eg.: /promotions/new
public ActionResult New() { ... }
// eg.: /promotions/edit/5
[Route("edit/{promoId:int}")]
public ActionResult Edit(int promoId) { ... }
public void Internal() { ... }
}
and I want Internal not to be routed.
I would have expected to find a [DoNotRoute] or [Ignore] attribute, but I didn't find anything like that.
Use the [NonAction]
attribute:
[NonAction]
public void Internal() { ... }