title: NETCORE MVC - How to work with nested, multi-parameterized routes
body: <p>Looking for best practices when working with nested routes in .NET Core MVC.</p>
  
  <p>Let's say <code>CampusController.cs</code> works with a base model:</p>
  
  <pre><code>[Route("api/campus/")]
  public class CampusController : Controller
  {
      ...
      [HttpGet]
      [Route("{campusId}")]
      public IActionResult GetCampusInfo ([FromQuery]int campusId) { ... }
  }
  </code></pre>
  
  <p>And <code>BuildingController.cs</code> works with a child model:</p>
  
  <pre><code>[Route("api/campus/{campusId}/building")]
  public class BuildingController : Controller
  {
      ...
      [HttpGet]
      [Route("{buildingId}")]
      public IActionResult GetBuilding ([FromQuery]int buildingId) { ... }
  
      [Route("{buildingId}/")]
      public IActionResult GetBuilding ([FromQuery]int buildingId) { ... }
      ....
      (more Action Methods)
  }
  </code></pre>
  
  <p>If <code>buildingId</code> maps directly to the database it could retrieved even if the provided <code>campusId</code> isn't the parent. To keep the URL clean when calling <code>/api/campus/{campusId}/building/{buildingId}</code> I'd like to validate <code>{campusId}</code> and return a 4xx coded IActionResult if it's invalid. There has to be a better way than including validation logic in every Action Method inside <code>BuildingController</code>.</p>
  
  <ul>
  <li>Is there a way to cascade multiple Action methods on different controllers? So that a validation method on <code>CampusController</code> would be called first and in turn call a method on<code>BuildingController</code>?</li>
  <li>Is there a way to have a controller-level verification of <code>campusId</code> that could short circuit and return a ActionResult if validation fails?</li>
  </ul>
  
  <p>EDIT: When I refer to validation logic I mean API signals; not the business-logic that actually determines if campusId is/isn't valid.</p>
  
  <p>Thanks in advance!</p>