Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • wakeboy 3 posts 24 karma points
    Nov 06, 2013 @ 02:12
    wakeboy
    0

    Problems Rendering Partial Views With EditorTemplates From Macros

    I am attempting to integrate a custom form in a partial view with Umbraco and I am getting an error when I render the partial view though a macro.

    Test code I am using in my template 

    @using ATDW.myEvents.CMS.Models.Account
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Master.cshtml";
    }
    <h1>
        @Umbraco.Field("title")    
    </h1>
    <div>
        @Umbraco.Field("primaryContent")
    </div>
    <div>
        @Umbraco.Field("secondaryContent")
    </div>
    @Html.Partial("RegisterView", new GenericAccountModel("RegistrationLayout"), new ViewDataDictionary { { "template", "RegistrationLayout" } })
    @Umbraco.RenderMacro("Register")
    The Register.cshtml (MacroPartial)
    @using ATDW.myEvents.CMS.Models.Account
    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @Html.Partial("RegisterView", new GenericAccountModel("RegistrationLayout"), new ViewDataDictionary { { "template", "RegistrationLayout" } })
    The RegisterView.cshtml (PartialView)
    @using ATDW.myEvents.CMS.Controllers.Account
    @inherits UmbracoViewPage<ATDW.myEvents.CMS.Models.Account.GenericAccountModel>
    @using (Html.BeginUmbracoForm<AccountController>("Register"))
    {
        <fieldset>
            @for (int i = 0; i < Model.Controls.Count; i++)
            {
                if (Model.Controls[i].Visible)
                {
                    if (Model.Controls[i].Type == "legend")
                    {
                        <legend>
                            @Html.Raw(Model.Controls[i].Label)
                        </legend>
                    }
                    else
                    {
                        @Html.HiddenFor(ctl => ctl.Controls[i].Id)
                        @Html.EditorFor(ctl => ctl.Controls[i])
                    }
                }
            }
                
            @Html.Hidden("template", ViewData["template"].ToString())
        </fieldset>
    }

     

    The @Html.Partial renders in the view renders the form correct.  
    The @Umbraco.RenderMacro renders and error because it can't find the partial view.
    Error Log
    2013-11-06 10:51:11,193 [25] WARN  umbraco.macro - [Thread 32] Error loading Partial View (file: ~/Views/MacroPartials/Register.cshtml). Exception: System.InvalidOperationException: The partial view 'RegisterView' was not found or no view engine supports the searched locations. The following locations were searched:
    ~/Views/PartialViewMacro/RegisterView.aspx
    ~/Views/PartialViewMacro/RegisterView.ascx
    ~/Views/Shared/RegisterView.aspx
    ~/Views/Shared/RegisterView.ascx
    ~/Views/PartialViewMacro/RegisterView.cshtml
    ~/Views/PartialViewMacro/RegisterView.vbhtml
    ~/Views/Shared/RegisterView.cshtml
    ~/Views/Shared/RegisterView.vbhtml
       at System.Web.Mvc.HtmlHelper.FindPartialView(ViewContext viewContext, String partialViewName, ViewEngineCollection viewEngineCollection)
       at System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection)
       at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
       at ASP._Page_Views_MacroPartials_Register_cshtml.Execute() in xxxxxxxxx\Views\MacroPartials\Register.cshtml:line 4
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
       at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
       at Umbraco.Web.Mvc.ControllerExtensions.RenderViewResultAsString(ControllerBase controller, ViewResultBase viewResult)
       at Umbraco.Web.Macros.PartialViewMacroEngine.Execute(MacroModel macro, INode currentPage)
       at umbraco.macro.LoadPartialViewMacro(MacroModel macro)
       at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
    I have tried to move RegisterView.cshtml to the directories listed in the log, the view then loads but when the view loads it can't load the incorrect EditorTemplates and the form is not displayed as expected.
    Any help would be greatly appreciated.
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Nov 06, 2013 @ 08:31
    Jeavon Leopold
    0

    Hi and welcome to Our!

    You can be explicit with your partial path when calling Html.Partial, e.g

    @Html.Partial("~/Views/Myfolder/RegisterView.cshtml", new GenericAccountModel("RegistrationLayout"), new ViewDataDictionary { { "template", "RegistrationLayout" } })
    

    That might be helpful?

    Jeavon

  • wakeboy 3 posts 24 karma points
    Nov 07, 2013 @ 07:16
    wakeboy
    0

    Thanks for the reply Jeavon.

    Using the explicit path loads partial view from the MarcoPartial,  but the correct editor templates are still not loaded is not loaded.

    The result I get when rendering from the @Html.Partial

     

    The output from the MacroRender Is below.

     

     

    The form works in an existing MVC application, so its not using the Umbraco Membership Provider for registrations.

     

     

     

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft