connectseekers.com

Saturday, 25 March 2017

Mvc Routing Multiple Optional Parameters

3/25/2017 - By Pranav Singh 0

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.

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.









About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Design By:
back to top