Forms loaded via ajax call

Vote:
 

Hi 

I have an problem with loading forms via ajax call. In project we have an form which will be dispalyed on dialog. When rendering partial view during ajax call exception occurs :

[NullReferenceException: Object reference not set to an instance of an object.]
   EPiServer.Forms.Controllers.FormContainerBlockController.RegisterResources(List`1 scripts, List`1 css) +872
   EPiServer.Forms.Controllers.FormContainerBlockController.RegisterScriptResources(FormContainerBlock formContainerBlock) +160
   EPiServer.Forms.Controllers.FormContainerBlockController.Index(FormContainerBlock currentBlock) +502
   lambda_method(Closure , ControllerBase , Object[] ) +141
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +279
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +34
   System.Web.Mvc.Async.<>c__DisplayClass42.b__41() +32
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +41
   System.Web.Mvc.Async.<>c__DisplayClass39.b__33() +79
   System.Web.Mvc.Async.<>c__DisplayClass4f.b__49() +385
   System.Web.Mvc.Async.<>c__DisplayClass4f.b__49() +385
   System.Web.Mvc.Async.<>c__DisplayClass4f.b__49() +385
   System.Web.Mvc.Async.<>c__DisplayClass4f.b__49() +385
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.<>c__DisplayClass2a.b__20() +32
   System.Web.Mvc.Async.<>c__DisplayClass25.b__22(IAsyncResult asyncResult) +184
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
   System.Web.Mvc.<>c__DisplayClass1d.b__18(IAsyncResult asyncResult) +27
   System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +22
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52
   System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +22
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
   System.Web.Mvc.<>c__DisplayClass8.b__3(IAsyncResult asyncResult) +41
   System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +22
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
   System.Web.Mvc.<>c__DisplayClass4.b__3() +15
   System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +26
   System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +1704

[HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.]
   System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +2321
   System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +137
   System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +33
   System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +575
   EPiServer.Web.Mvc.PartialRequest.RenderAction(HtmlHelper helper, String action, String controller, Object routeValues) +84
   EPiServer.Web.Mvc.Html.IContentDataExtensions.RenderContentData(HtmlHelper html, IContentData contentData, Boolean isContentInContentArea, TemplateModel templateModel, IContentRenderer contentRenderer) +575
   EPiServer.Web.Mvc.Html.ContentAreaRenderer.RenderContentAreaItem(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem, String templateTag, String htmlTag, String cssClass) +1385
   EPiServer.Web.Mvc.Html.ContentAreaRenderer.RenderContentAreaItems(HtmlHelper htmlHelper, IEnumerable`1 contentAreaItems) +193
   EPiServer.Web.Mvc.Html.ContentAreaRenderer.Render(HtmlHelper htmlHelper, ContentArea contentArea) +331
   ASP.util_views_shared_displaytemplates_contentarea_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in C:\Projekty\grantthornton\GrantThornton.Interface.Web\Util\Views\Shared\DisplayTemplates\ContentArea.ascx:4
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +260
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +79
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +159
   System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +75
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +79
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4124

Unfortunetly we are using quite old version of forms (4.3.0) and we can't upgrade to higer version :( 

Because as I understand problem i with loading some scripts or other dependent content.

So question is have somebody struggled with this problem. Or know how partial view should be created to enable forms on modal popup loaded via xjax?

Right now partial view is quite simple :

@model SubscribeOverlayViewModel

@Html.PropertyFor(m => m.SubscribeBlock.FormsArea)

Have an nice day :)

#190688
Apr 16, 2018 9:35
Vote:
 

Can you provide us your implementation code so that we can have a look ?

#190810
Edited, Apr 17, 2018 12:32
Vote:
 

Hi Quan

Javascript is standard jQuery call for partial view.

On server site we have standard ASP.MVC controller

 public class SubscribeOverlayController : Controller

with Index Action :

 public ActionResult Index(int contactPageId, string currentCulture)
        {
            var contactPage = BaseDependencies.ContentRepository.Get<ContactPage>(new PageReference(contactPageId), new LanguageSelector(currentCulture));
            return PartialView("~/Views/Partial/SubscribeOverlay.cshtml", new SubscribeOverlayViewModel(contactPage, currentCulture));
        }

And during rendereing :

@Html.PropertyFor(m => m.SubscribeBlock.FormsArea)

We recive above errors. 

FormsArea implementaion :

[Display(Name = "Forms", Description = "Insert forms", GroupName = TabGroupNames.EpiForms)]
        [AllowedTypes(typeof(FormContainerBlock))]
        [AllowedBlocks(new[] { typeof(FormContainerBlock) })]
        [CultureSpecific]
        public virtual ContentArea FormsArea { get; set; }

I understand that probelm is probably in partial view rendereing. And i iam trying to find some solution. 

#190821
Edited, Apr 17, 2018 14:30
Vote:
 

Partial view cannot be rendered in itself. Do you have the parent view referencing this view? 

#190864
Apr 17, 2018 21:33
Vote:
 

In stanard templated view yes, but as i have mentioned in my first post this view is recived by axax call. 

In this situation I have an button, on clik we make asynchronous (via jQuery $.ajax() method) call for partial view

#190879
Apr 18, 2018 9:17
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.