This article
will show you how you can use mvc routing multiple optional parameters. In this
I will show you how you can manage multiple parameter inside the routing file.
So here is the code of your routing file.
So here is the code of your routing file.
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection
routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{name}/{type}",
defaults: new { controller = "Home", action = "Index", name = UrlParameter.Optional, type = UrlParameter.Optional }
);
}
}
|
Now we will
test the routing. For this we will first create controller file and add the
below code.
[HttpGet]
public ActionResult
Index(string
name, string
type)
{
return View();
}
|
Now run the
application to check the output. When you execute without parameter value you
will get null.
Now change
the url as shown below.
Now check
the output.
0 comments:
Please let me know your view