0

The url format is:

http://0.0.0.0:5000/?id=author_name&id2=book_name&id3=123

I tried to make the roate for it, but it doesn't work:

   routes.MapRoute(
                    name: "default",
                    template: "{controller=Main}/{action=Index}/{id?}&{id2?}&{id3?}");

And the method is:

   public IActionResult Index(string id, string id2, string id3)
   {
        return View();
   }

How do I set the proper route for passing 3 parameters?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
mr_blond
  • 1,586
  • 2
  • 20
  • 52
  • I'm pretty sure in your case you don't need to put the querystring in the route template. It'll be done automatically by mvc. – the_lotus Sep 03 '19 at 15:08
  • @the_lotus so route template should be `template: "{controller=Main}/{action=Index}")` ? – mr_blond Sep 03 '19 at 15:13

1 Answers1

2

I'm pretty sure in your case you don't need to put the querystring in the route template. It'll be done automatically by mvc. Just use the "normal" route.

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Main", action = "Index", id = UrlParameter.Optional }
        );

The variables in the get are automatically passed as parameters.

   public IActionResult Index(string id, string id2, string id3)
   {
        return View();
   }
the_lotus
  • 12,668
  • 3
  • 36
  • 53