0

I have this route map defined.

  routes.MapRoute("default", // route name
            "{controller}/{action}/{id}", // url with parameters
            new { controller = "home", action = "index", id = UrlParameter.Optional }, // parameter defaults
            new string[] { "mobilesurveys.mt.controllers" }
        );

This will work perfectly. now I want to add another routemap

   routes.MapRoute("couponreedem", // route name
            "{controller}/{action}/{clientname}", // url with parameters
            new { controller = "Rc", action = "index", id = UrlParameter.Optional }, // parameter defaults
            new string[] { "mobilesurveys.mt.controllers" }
        );

i have defined like this. Here Rc is my controller. and I am giving the url as .com /Rc/Rc/sammy

and method in the controller defined as

  public ActionResult Rc(string clientname)
    {

        viewModel =dataRc.ProductCategoryGet();
        return View(viewModel);
    }

clientname will be always null. How to add another route while the existing route not be disturbed.

Thanks.

2
  • 1
    Seems like both of your routes are identical, why do you need the second one? Commented Jun 13, 2012 at 15:25
  • Unless you're hung up on having the parameter as "clientname" rather than, "id" - I would just stick with "id" and you won't need to define a second route (couponreedem). Else, fix the parameter in your second route map (couponreedem) - changing "id = Url.Paremeter.Optional" to "clientname = Url.Paremeter.Optional". Also, unless you're using "Areas", you don't need to specify the namespace for your controllers.
    – anAgent
    Commented Jun 13, 2012 at 16:17

1 Answer 1

1

It actually looks identical. But in case you want a new one you can try something like this, and it should be above the default one.

 routes.MapRoute("couponreedem", // route name
            "RC/{action}/{clientname}", // url with parameters
            new { controller = "Rc", action = "index", clientname = UrlParameter.Optional }, // parameter defaults
            new string[] { "mobilesurveys.mt.controllers" }
        );

That will fix the route with RC/... Also your action should be named Index

  public ActionResult Index (string clientname)
    {

        viewModel =dataRc.ProductCategoryGet();
        return View(viewModel);
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.