This project is read-only.

Returning View from POST method loses the ID in the URL

Topics: Core, Customizing Orchard, General
Jun 17, 2014 at 11:54 AM
Hello, I am having a very small problem with my module in Orchard. When I post data to (for example) the Edit action in my controller, I check that the Model is valid and eventually return the View if it's not (much like I do with all other MVC projects).

What happens here is that the URL of the returned View changes to not show the ID anymore, but it shows an extra "Edit".

So for example I go to
When I hit "Submit" it posts back to my Controller:
public ActionResult Edit(BasicInfoStandard model) {
    if (ModelState.IsValid) {
        Services.Notifier.Add(NotifyType.Success, T("Basic Information updated succesfully."));
        return RedirectToAction("Details", "Cases", new { id = model.StudyCaseId });
    else {
        Services.Notifier.Add(NotifyType.Error, T("There is an error with the entered data."));
        return View(model);
Everything goes as expected, but when the page is shown I can see the URL is like this:
Any ideas why? In the Routes I have only defined this, where the area is my module name.
new RouteDescriptor {
    Name = "MyProject",
    Priority = 5,
    Route = new Route(
        new RouteValueDictionary {
            {"area", areaName},
            {"controller", "Cases"},
            {"action", "Index"},
            {"id", UrlParameter.Optional}
        emptyConstraints, areaRouteValueDictionary, mvcRouteHandler)
Jun 17, 2014 at 12:51 PM
So, sorry for bothering you but apparently the problem was in the View and in how the form is created:
@using (Html.BeginFormAntiForgeryPost("Edit", FormMethod.Post, new { @class = "form-horizontal" })){
This outputs the following tag, where you can see the form action being wrong:
<form action="Edit" class="form-horizontal" method="post" novalidate="novalidate">
    <input name="__RequestVerificationToken" type="hidden" value="H-fPeL9E6vEAKqsuNWIjzQY6kypb_h2tpJJg_nezkgLm6nEW_e2hGtMokW9zqVvuva7PaCtKsf-Tyu77LX_89fa-au4qPZuTSRGuAmTNPeMhUxaREdotVDwoajTDNMr969FoeYKTgzytDgYeeu4cKB87ly5z_-8PLMIxCB798go1">
I can fix it in two ways, either:
@using (Html.BeginFormAntiForgeryPost(Model.Id.ToString(), FormMethod.Post, new { @class = "form-horizontal" })){
or using the normal BeginForm and then adding the AntiForgery token:
@using (Html.BeginForm("Edit", "BasicInfo", FormMethod.Post, new { @class = "form-horizontal" })) {
I was wondering if this is expected from the Orchard helper or if there is a more clever way of using it that I am missing.