Can you have your form handle method be named the same as your default action? It would be much easier for Mvc to route through:
@using (Html.BeginForm(null, null, new { language = ContentLanguage.PreferredCulture.Name }, FormMethod.Post) { ... }
public class SomePageController : PageControllerBase<SomePage>
{
[HttpGet]
public ActionResult Index(SomePage currentPage)
{
return View(model);
}
[HttpPost]
public ActionResult Index(PostModel model)
{
return RedirectToAction("Index");
}
}
/sv/super-page goes to SomePageController's index action method right? If that's the case then /sv/super-page/postdata is correct. What does your http body (of the request) look like?
Frederik
Yes that's true Frederik.
I see what's going wrong now, from /sv/super-page it posts to /super-page/postdata. The /sv/ part is missing and therefore it returns 404.
How do I include that?
Like in Valdis' example, with new { language = ContentLanguage.PreferredCulture.Name } (this is the additional route parameter).
Frederik
Thanks for pointing that out, I missed that.
Thanks for your help Valdis and Frederik!
Lets say I have this controller,
The url to this page could be localhost:37000/sv/super-page
And in the view I create a form using @using Html.BeginForm("PostData", "SomePage", null, FormMethod.Post) {}
I would expect that to work as that's how MVC usually works but with EPi it doesn't.
The form is posting to /sv/super-page/postdata which doesn't correspond to the SomePageController.
When posting forms in EPiServer MVC, how to I post them to the correct controller and action method?