Route provider only accepts integers

Posted: November 14, 2017 at 11:38 AM Quote #196170
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
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: November 14, 2017 at 2:21 PM Quote #196174
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 post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Premium support services
  • Dedicated premium support services provided by core developers are intended for persons who run mission critical websites, work on projects with tight deadlines, or want to get dedicated support.
Professional services
  • Want to open a new store? Want to take your store to the next level? Need a custom extension? We can customize nopCommerce to fit your store perfectly. Request a quote to get started.