Widget with Controller [HttpPost] redirects to Module/Folder1/View1 if there is an error

Topics: General, Troubleshooting, Writing modules
Nov 20, 2013 at 7:54 PM
Edited Nov 20, 2013 at 7:56 PM
I set up a driver-less/part-less/placement-less widget using a [Themed] controller thusly:
public ActionResult View1()
    vary myViewModel = MyViewModel();
    // Note: I use a ShapeTemplateHarveter that allows the path "Folder1"
    dynamic shape = _orchardServices.New.Folder1_View1(MyModel: myviewModel);
    return new ShapeResult(this, shape);

public ActionResult View1POST(string submitButton)
    if ((submitButton != null) && ModelState.IsValid)
        // Code for saving to DB
        return RedirectToAction("Submitted");
        dynamic shape = _orchardServices.New.Folder1_View1(MyModel: myViewModel);
        return new ShapeResult(this, shape);
To make this a widget that I could add to a page through Admin > Widgets, I added this to my migration:
    cfg => cfg
        .WithSetting("Stereotype", "Widget")
        .DisplayedAs("My Widget"));
and I did this in a handler:
protected override void BuildDisplayShape(BuildDisplayContext context)

    if (context.ContentItem.ContentType == "MyWidget")
        dynamic shape = context.New.Folder1_View1();
        context.Shape.Folder1_View1 = shape;
I added the widget to a page via Admin > Widgets and it displays fine. However, I have a "Submit" button in the view. When I click submit with empty fields (which are required) or make any other purposeful errors, I expect the page to be refreshed with the model validation errors.

Instead it redirects to the ~/MyModule/Folder1/View1 url with the model validation errors.

I am not sure how to make this work as I expect. If I fill out the widget on the page with no errors, I get the expected behavior I have coded, which is a redirect to a "Submitted" page.

I deleted routes for the View1 because when I got the validation error it would go to the route that I set up (~/Folder1/View1).

Any thoughts on how to get it to validate on the page it's on? Thanks.