Fixed an issue with a potentially null controller.

When the indexing background task displays content with a Form element, the driver was throwing a NRE because of a null controller.
This commit is contained in:
Sipke Schoorstra
2015-04-21 17:38:27 +02:00
parent 5d7988650e
commit b44b4e9170

View File

@@ -130,15 +130,15 @@ namespace Orchard.DynamicForms.Drivers {
protected override void OnDisplaying(Form element, ElementDisplayContext context) {
var controller = _currentControllerAccessor.CurrentController;
var values = controller.FetchPostedValues(element);
var modelState = controller.FetchModelState(element);
var modelState = controller != null ? controller.FetchModelState(element) : default(ModelStateDictionary);
if (modelState != null && !modelState.IsValid) {
// Read any posted values from the previous request.
var values = controller.FetchPostedValues(element);
_formService.ReadElementValues(element, new NameValueCollectionValueProvider(values, _cultureAccessor.CurrentCulture));
// Add any model validation errors from the previous request.
controller.ApplyAnyModelErrors(element, modelState);
controller.ApplyAnyModelErrors(element, modelState);
}
// Assign the binding content type to each element within the form element.