MVC - C# -Passing query string (Optional & Default Parameters)

  • Passing regions as optional parameter

     namespace MvcVersionFinder.Controllers



    {
       public class HomeController : Controller



        {
           public string Index(string id, int? regions)


           {


           return id + "Test" + regions.ToString ();


           }
        }
     }


Usage - http://localhost:81/MvcVersionFinder/?id=2&&regions=4    2Test4


        http://localhost:81/MvcVersionFinder/?id=2               2Test


  • Passing regions with Default value

      public string Index(string id, int regions =2)
        {
            return id + "Test" + regions.ToString();
        }

Usage - http://localhost:81/MvcVersionFinder/?id=2     2Test2
        http://localhost:81/MvcVersionFinder/?id=2&&regions=4    2Test4

No comments:

Post a Comment