Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
1. Get the url to the delivery page you want to redirect to using the UrlResolver.
var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>(); var url = urlResolver.GetUrl(deliverycontentReference, language);
2. Redirect to that url (avoid redirecting directly to the controller and action if you are not in the same controller). Redirect to a matching page instead and that call will end up in the right controller with correct route values etc
return Redirect(url);
I came across an issue where I am not able to navigate to the second page on HttpPost. I am not able to get the correct route values.
This is my HttpPost code. I tried different option to navigate to DeliveryController and action Index.
public ActionResult CheckOut(CurrencyViewModel model)
{
// The below return statement, changes the url as /Delivery/Index?language=en and I am getting 404 error.
// return RedirectToAction("Index", "Delivery", new { language = ContentLanguage.PreferredCulture.Name });
// With the below return statement, the page simply refresh it.
// PageData startPage =().Get(ContentReference.StartPage);
//ServiceLocator.Current.GetInstance
// // get URL of the start page()
// string startPageUrl = ServiceLocator.Current.GetInstance
// .GetVirtualPath(startPage.ContentLink, startPage.LanguageBranch);
// return Redirect(startPageUrl);
// With the below return statement, the page simply refresh it.
return RedirectToAction("Index", new
{
language = ContentLanguage.PreferredCulture.Name,
node = ControllerContext.RequestContext.GetContentLink()
});
This is my CurrencyViewModel
public class CurrencyViewModel : BaseViewModel
{
public CurrencyPage CurrentPage { get; set; }
[Required]
public string Amount1 { get; set; }
[Required]
public string Amount2 { get; set; }
}
My currency index.cshtml has the below form and it is hitting the CurrencyController and action method checkout.
@using (Html.BeginForm("CheckOut", "Currency", new { language = ContentLanguage.PreferredCulture.Name, FormMethod.Post }))
{}
Can anyone explain me simple solution to implement the routing.