Reputation: 13636
Here is my route:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Sensor", action = "Index", id = UrlParameter.Optional }
);
}
Here is my action:
public ActionResult Index(string id)
{
try
{
return View();
}
catch (Exception)
{
return View("Error");
}
}
}
When the page is loading I get this url:
http://localhost:2326/
Now I need to pass parameters to Index action:
http://localhost:2326/"123456"
When I make this I get error.
I guess there is some problem with routing.
How can I pass parameter to the Index Action?
Upvotes: 0
Views: 46
Reputation: 386
You can pass multiple parameters using:
http://localhost:2326/?id=123456¶m2=text¶m3=something
or
http://localhost:2326/Sensor/Index/123456/Param2/text/Param3/something
And of course you need to add an extra route to handle the amount of parameters
routes.MapRoute(
"MoreParams",
"{controller}/{action}/{id}/{param2}/{param3}",
new { controller = "<controllername>", action = "Index", id = "", param2 = "", param3 = "" }
);
and a method.
Upvotes: 1