Adding another route in Asp.net mvc3 not working

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.

Answers


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);
    }

Need Your Help

Show QCalendarWidget for Shamsi (Jalali) in Python and pyqt

python qt pyqt

I want to know QCalendarWidget(pyqt and in python) for Persian displayed What should I do?

Gmail does not allow margin property

html css gmail newsletter

I want apply margin property for my html newsletter