Access FormViewModel from Surface Controller handler
How do I access the values from the Umbraco FormViewModel from my custom handler in my surface controller? For instance, I create a new Surface Controller derived from UmbracoFormsController and then create a custom Handler as follows:
public class TestSurfaceController : Umbraco.Forms.Web.Controllers.UmbracoFormsController
{
[HttpPost]
[ValidateCaptcha]
[ValidateInput(true)]
public void TestHandler(FormViewModel model, bool captchaIsValid)
{
if (ModelState.IsValid)
{
var test = 1;
}
}
}
However, when this gets called from my Forms.cshtml partial view, the only values I can get from the FormViewModel are FormID and FormName (see attached screen shot)
I can get more data on the OnFormHandled method, but would like to process data pre handling (see screenshot)
Yes I did. In the Umbraco.Forms.Web assemly, you can get the answer there.
I first had to create my own
I extracted the GetForm method, and then used model.Build(form), so like this:
public class TestSurfaceController : Umbraco.Forms.Web.Controllers.UmbracoFormsController
{
private Form GetForm(Guid formId)
{
using (FormStorage formStorage = new FormStorage())
return formStorage.GetForm(formId);
}
[HttpPost]
[ValidateCaptcha]
[ValidateInput(true)]
public void TestHandler(FormViewModel model, bool captchaIsValid)
{
var form = this.GetForm(model.FormId);
model.Build(form);
//this will now have a built form model
if (ModelState.IsValid)
{
var test = 1;
}
}
}
Access FormViewModel from Surface Controller handler
How do I access the values from the Umbraco FormViewModel from my custom handler in my surface controller? For instance, I create a new Surface Controller derived from UmbracoFormsController and then create a custom Handler as follows:
}
However, when this gets called from my Forms.cshtml partial view, the only values I can get from the FormViewModel are FormID and FormName (see attached screen shot)
I can get more data on the OnFormHandled method, but would like to process data pre handling (see screenshot)
anyone able to assist?
Did you ever solve this?
Yes I did. In the Umbraco.Forms.Web assemly, you can get the answer there.
I first had to create my own I extracted the GetForm method, and then used model.Build(form), so like this:
is working on a reply...