Route provider only accepts integers

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Greetings.  I have a custom route provider that looks like this:

routes.MapLocalizedRoute("AddProductToCart-Url",
    "addproducttocartfromwebsite/{product_id_list}/{shoppingCartTypeId}/{quantity}",
    new { controller = "ShoppingCart", action = "AddProductToCart_Catalog_FromUrl" },
    new { product_id_list = @"\d+", shoppingCartTypeId = @"\d+", quantity = @"\d+" },
    new[] { "Nop.Web.Controllers" });


If I put a number in for "product_id_list", I see the action method getting executed.

What I ultimately need to do is pass some sort of delimited list of IDs where it says "product_id_list".  Right now, this only works if I pass in an integer.  If I pass in a list or even just some characters that aren't numbers, my action doesn't even get executed: I just get taken to a 404 page and I never see the method get called.  

My action method looks like this:

public ActionResult AddProductToCart_Catalog_FromUrl(string product_id_list, int shoppingCartTypeId,
            int quantity, bool forceredirection = false)
{
    // stuff
}


Is there some way to pass in strings instead of integers here?

Thanks!

Jeremy
6 years ago
Guys, I got this figured out.  It turns out that the

@"\d+"

is like a regex to enforce some validation.  

I found that I can make it work by either removing

product_id_list = @"\d+"

completely or changing it to

product_id_list = @".*"

Have a great day!

Jeremy
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.