ProgrammerGuide.Net | Step by Step Programmer Guide

How to Apply Multiple constraints to a Parameter in MVC Attribute Routing? | ASP.Net MVC Interview Question

  • You can apply multiple constraints to a parameter, separated by a colon.
  • Well,It’s like this  [Route(“Pet/{petId:int:min(1)}”)]


     public class PetController : Controller

        // eg: /Pet/8
        public ActionResult GetSpecificPetById(int petId)
            return View();

Key points of the above code

  • In the above example,You can’t use  /Pet/10000000000 ,because it is larger than int.MaxValue
  • And also you can’t use /Pet/0 ,because of the min(1) constraint.

Please click here for related products on Amazon!


Add comment

Want to Check Celebrities News?