This project is read-only.

Extending Forms

Topics: Customizing Orchard
Feb 19, 2015 at 5:06 PM
I've seen many people trying to get the data from a form into a specified action of a controller but am unable to get this working the right way in Orchard. In the methods I was able to find most people had their form as part of a view which submits the form to the controller and action specified. With the following:
using (@Html.BeginForm("myMethod", "Home", FormMethod.Post))
I would like to accomplish this using the custom forms already built into Orchard instead of having to create each form in a view. I tried creating a workflow that performs a web request, to a route I created for my controller and action, whenever my form is submitted and passes in the form data to the request. This successfully got my form data into my controller, however it will not return the view from the controller that should be used to display the results, I run some math on the form data and need to display a final result, because it is just a web request. Is there some way to pass my form data into my controller and have that controller run the required math and then return a view with the results? Thank you.
Feb 21, 2015 at 10:04 AM
Related thread:

When the WebRequestActivity receives the response from your HTTP request to your controller, it stores that response in the workflow like this:
workflowContext.SetState("WebRequestResponse", response.Content.ReadAsStringAsync().Result);
If your controller returns the full page output, I imagine you could write your own activity that Response.Writes the response stored as part of the workflow.
Or you could have your form be submitted using AJAX, which would trigger the workflow, which response.writes the result, which you then inject into the DOM as part of your AJAX callback.
Marked as answer by emeraldarcher on 2/23/2015 at 10:39 AM
Feb 24, 2015 at 5:02 PM
Edited Feb 24, 2015 at 5:27 PM
Thanks for the help sfmskywalker. I was able to get it working.