[RESOLVED]Routing with parameter conflicts issue

MY route config :

routes.MapRoute(
"LastTwoRoute",
"thong-ke-ket-qua-xo-so-2-so-cuoi/{cityID}/{pnumbers}/{pdays}/{ponlySpecial}",
new { controller = "LastTwo", action = "Index", 
        cityID = "MB", 
        pnumbers = "",
        pdays = 1000,
        ponlySpecial = false
});

The controller :

    [HttpGet]
    public ActionResult Index(string cityID, string pnumbers, int pdays, bool ponlySpecial)
    {

 [HttpGet]
public ActionResult Index(string cityID, string pnumbers, int pdays, bool ponlySpecial)
{

    LastTwoParameters lastTwoParameters = new LastTwoParameters();
    lastTwoParameters.listCities = Common.GetDropDownCitiesList();
    lastTwoParameters.Numbers = pnumbers; 
    lastTwoParameters.Days = pdays;
    lastTwoParameters.OnlySpecial = ponlySpecial; 
    lastTwoParameters.listLastTwoResult = new List<getReport_LastTwo_Result>();

    if (TempData["Redirection"] != null || !string.IsNullOrEmpty(pnumbers) )
    {
        if (!string.IsNullOrEmpty(cityID) && pdays > 0)
        {
            using (KQXS context = new KQXS())
            {
                lastTwoParameters.listLastTwoResult = context.getReport_LastTwo(cityID, pnumbers, pdays, ponlySpecial).ToList();
            }
        }

    }
    return View(lastTwoParameters);
}

[HttpPost]//Run action method on form submission
public ActionResult Index(List<Cities> c, string cityID, string numbers, int days, bool onlySpecial)
{
    TempData["Redirection"] = true;
    return RedirectToRoute("LastTwoRoute", new { 
            cityID = (string.IsNullOrEmpty(cityID) ? "MB" : cityID ),
            pnumbers = (string.IsNullOrEmpty(numbers) ? string.Empty : numbers) , 
            pdays = (days == 0 ? 1000 : days), 
            ponlySpecial = onlySpecial});
}

When I frist access the controller :

and hit the submit button without entering/modifying any parameter, there are no errors :

but if I modify the third or the fourth parameter, I will have this error :

No route in the route table matches the supplied values.

I debuged the code, and at the line RedirectToRoute
in HttpPost
every parameters are about the same except the parameter that I modified. I can’t think of a reason why is this error happening!

If I enter/modified the second parameter (the second text box counting from top to bottom), I have no errors either!

Any help is greatly appreciated!

P/s : If this is not clarify enough for you because of my poor English, I can provide a screen video which records how I get the error!

Hi,

And the value supplied for the third and fouth parameters are a number and a boolean ? Could you copy/paste the url that fails so that we can see if it is supposed to match this route?

Thanks Patrice!

I solved it, by moving pnumbers to the end of the required parameters and mark it as optional :

            routes.MapRoute(
            "LastTwoRoute",
            "thong-ke-ket-qua-xo-so-2-so-cuoi/{cityID}/{pdays}/{ponlySpecial}/{pnumbers}",
            new { controller = "LastTwo", action = "Index", 
                    cityID = "MB", 
                    pnumbers = UrlParameter.Optional,
                    pdays = 1000,
                    ponlySpecial = false
            });

Leave a Reply