Hello,
I havn't tried this, but I have some tips what you can test to do.
1. Create a class that inherits from XFormPageUnknownActionHandler and register the class in the service locator (For<XFormPageUnknownActionHandler>().Use<MyClass>()).
2. Override ProcessXFormAction and replace the xFormHelper.GetXFormData with youre own code.
I know this is not a whole solution, but maby a startpoint. We do not have XForm support out of the box for Blocks in MVC.
To render xForm you should use @Html.DisplayForModel(new { XFormParameters = new XFormParameters { PostAction = "Post"} })
It will trigger your custom post action in the controller, and it will be before the data is posted.
In the controller you can do something like this:
[AcceptVerbs(HttpVerbs.Post)]
public virtual ActionResult Post(SomePageType currentPage, XFormPostedData xFormPostedData)
{
var xFormData = new XFormPageHelper().GetXFormData(this, xFormPostedData); //get xFormData that will be posted
xFormData.SetValue(set some values); //changing some values in the data to be posted
try
{
XFormActionHelper.DoAction(xFormData, xFormPostedData, true); //post data
TempData["success"] = "Form submitted";
}
catch (Exception exception)
{
ModelState.AddModelError("ProcessXFormAction", exception.Message);
}
return View("Index", model);
}
Hope this helps..
Phil
Hi!
I need to create XForm block element that can be added on any page that has block area. We are using ASP.NET MVC 4.
The first problem is that the XForm action url is for the block controller, e.g. http://localhost/XFormBlock/XFormPost?.. Well that's easy to fix with a custom routepath.
The second problem is that XFormPageHelper.GetXFormData-method assumes that xform is posted for a PageController, and fails when page is not found.
I guess it might be possible to make this work by adding contentId-parameters to action link, but it would be ugly as hell. There's got to be more beatiful solution for this, or is there?