Try our conversational search powered by Generative AI!

Routing on forms

Vote:
 

Hi, 

I'm having trouble with routing when posting form from another language other than default. 
For example . I've got this

@using (Html.BeginForm("AddToCart", null , new { node = Model.Variation.ContentLink}, FormMethod.Post, new {id = "AddToCartForm"}))

which generates my post form

which works fine, but when I switch to Russian language for example. Html.BeginForm generates action 

Now I tried different routings for this, but nothing changed. I still get 404 not found error.
Should the routing be something like this?

            RouteTable.Routes.MapContentRoute(
                "defaultRouteWithLanguage",
                "{lang}/{node}/{action}",
                new { action = "Index" });
            

What should I look for or try and change? 
Using episerver 9

Regards,
A

#140768
Oct 29, 2015 15:28
Vote:
 

Hi, 
I figured it out. The post address on form was generated wrong. I managed to get it right with UrlResolver,
<form action="@UrlResolver.Current.GetUrl(Model.Variation.ContentLink)AddToCart" id="AddToCartForm" method="post">

but now I'm having a new problem . 

After Post I try to RedirectToAction, but again 404 Not Found error pops up. It tries to redirect to default address again. 

How can I prevent it from redirecting to 
http://localhost:44300/ru/kataloog/elektroonika/telefonid/nuti/4jasuuremad/4-ekraaniga-vee--ja-tolmukindel-nutitelefon-caterpillar-cat-b15q_dc9d1a1a/

And instead get the right address
http://localhost:44300/ru/kataloogRU/elektroonikaRU/telefonidRU/nutiRU/4suuremRU/smartfon-s-4-ekranom-vodo--i-pylenepronitsaemyy--caterpillar-cat-b15q_eb02a8d5/

My current Action looks like this. 

 [HttpPost]
        public ActionResult AddToCart(GeneralVariation currentContent, int amount)
        {
            VariationLogic variationLogic = new VariationLogic(_contentLoader, currentContent, _marketHelper, _logger);
            variationLogic.AddVaritationToCart(amount);

            return RedirectToAction("Index", new {node = currentContent.ContentLink});
        }



#140773
Edited, Oct 29, 2015 16:30
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.