Save Action on webforms for marketers throws exception

风流意气都作罢 提交于 2020-01-05 09:28:21

问题


I am using the latest version of Sitecore - 7.2 (rev. 140228) and the latest version of WFFM - 2.4 rev. 140923. So the problem is whenever I try to submit a form no matter what kind of save action I have, Sitecore throws exception:

Object reference not set to an instance of an object.

Description: An unhandled exception occurred.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   Sitecore.Forms.Mvc.Controllers.ModelBinders.FormModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +571
   System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +457
   System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +152
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +641

Some additional information. The latest version of WFFM supports MVC so in this scenario I use cshtml layout. This is the blog post where is described how to use MVC - THIS Despite it is for previous versions of SC it doesn't matter and the solution is applicable for the latest version.


回答1:


Think I have a solution for this.

I reverse engineered and debugged using a version of the controller and model binder I created after reflecting on the Sitecore.Forms.MVC classes using ILSpy.

Apparently the null reference is occuring when it hits this:

if (controllerContext.HttpContext.Request.RequestType == "POST" && formId != item.ID)

item is null. item is set in the line before:

Sitecore.Data.Items.Item item = RenderingContext.CurrentOrNull.PageContext.Database.GetItem(RenderingContext.CurrentOrNull.Rendering.DataSource);

The data source property is empty on the rendering. If you check your presentation details, you'll see that's because there is another field that is used to specify your form ID. Apparently this looks like a Sitecore bug. But an easy workaround is to set the form data source in both the form ID and the Data source property of the rendering.



来源:https://stackoverflow.com/questions/26094198/save-action-on-webforms-for-marketers-throws-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!