Ссылка на пользовательский элемент формы Sitecore пустая - PullRequest
0 голосов
/ 07 ноября 2019

Я пытаюсь создать пользовательский элемент формы List для отображения данных, которые я получаю от службы WCF. Ниже приведен код для ViewModel элемента управления TrimSize. Здесь _trimSizeManager.GetRules () возвращает список объектов, которые я получаю из WCF -

    public class TrimSizeViewModel : ListViewModel, IBindingSettings,ICustomViewModel
    {
        private ITrimSizeManager _trimSizeManager;
        public TrimSizeViewModel()
        {
            _trimSizeManager = ServiceLocator.ServiceProvider.GetService<ITrimSizeManager>();
        }
        public string BindingToken { get; set; }
        public bool PrefillBindingValue { get; set; }
        public bool DisableOnDataPrefill { get; set; }
        public string HelpText { get; set; }
        public string FieldAPIName { get; set; }
        public string DataParserClass => "ChoiceList";

        protected override void InitItemProperties(Item item)
        {
            base.InitItemProperties(item);
            this.InitBindingSettingsProperties(item);
            this.InitCustomViewModelProperties(item);
            Items.AddRange(_trimSizeManager.GetRules());
        }

        protected override void UpdateItemFields(Item item)
        {
            base.UpdateItemFields(item);
            this.UpdateBindingSettingsFields(item);
            this.UpdateCustomViewModelFields(item);
        }
    }

Когда я пытаюсь загрузить этот элемент управления на странице в разделе форм Sitecore, я получаю эту ошибку: трассировка стека -

[NullReferenceException: Object reference not set to an instance of an object.]
   ProjectABC.Forms.Fields.TrimSize.TrimSizeViewModel.InitItemProperties(Item item) in C:\codebase\ProjectABC\ProjectABC\Fields\TrimSize\TrimSizeViewModel.cs:29
   Sitecore.ExperienceForms.Mvc.Pipelines.GetModel.CreateModel.Process(GetModelEventArgs args) +301
   (Object , Object ) +13
   Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +483
   Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists) +235
   Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +21
Sitecore.Mvc.Pipelines.PipelineService.RunPipeline(String pipelineName, TArgs args) +194
   Sitecore.Mvc.Pipelines.PipelineService.RunPipeline(String pipelineName, TArgs args, Func`2 resultGetter) +160
   Sitecore.ExperienceForms.Client.Controllers.FormFieldController.RenderField(Guid fieldTypeId, Guid templateId) +625
   lambda_method(Closure , ControllerBase , Object[] ) +248
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +228
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +34
   System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +38
   System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +76
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +41
   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +71
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +387
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +387
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +387
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +38
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +188
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +73
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +39
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +43
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +73
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +648
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +213
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +131

Я проверил шаблоны TrimSize, направляющие идентификатора шаблона, элементы формы, направляющие элементов формы в редакторе содержимого Sitecore как для основного, так и для основного, и все это кажется правильным в Sitecore. Я не могу найти причину этой ошибки. Если я заменю ListViewModel на FieldViewModel, и методы модели списка комментариев, такие как Addrange, и изменю страницу просмотра, то код будет работать, и у меня нет этого исключения.

...