Copied to clipboard

Flag this post as spam?

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


  • Daniel Chenery 119 posts 465 karma points
    Sep 21, 2015 @ 16:27
    Daniel Chenery
    0

    Error loading Partial View script (file: ~/Views/MacroPartials/xxxx.cshtml)

    I've seen some related topics on the forum, but unfortunately none of the resolutions there seem to have solved my issue.

    I've a page (and for simplicities sake, I'll call it "MyPage"), with its own Controller.

    If I visit mysite.com/Controller/MyPage, all works fine and well, but as soon as I visit it with mysite.com/Controller/MyPage?MyQueryString=MyValue, I'm presented with the following error:

    Error loading Partial View script (file: ~/Views/MacroPartials/xxxx.cshtml)

    And here are some code snippets to help you out.

    Controller

    [EnsurePublishedContentRequest(6289)]
    public ActionResult MyPage(int? MyQueryString)
    {
        var ptmv = new MyViewModel();
        // All the complex logic here
        // Although the error will still occur even if I just 
        return View(ptmv);
    }
    

    Model

    public class MyViewModel : RenderModel
    {
        public UmbracoHelper umbracoHelper { get; set; }
        public IPublishedContent CurrentPage { get; set; }
    
        public MyViewModel() : this(new UmbracoHelper(UmbracoContext.Current)) { }
    
        public MyViewModel(UmbracoHelper Umbraco)
            : this(Umbraco.TypedContentAtRoot().Where(p => p.DocumentTypeAlias == "MyDocumentType").First())
        {
            umbracoHelper = Umbraco;
            CurrentPage = Umbraco.Content(Content.Id);
        }
    
        public MyViewModel(IPublishedContent content)
            : base(content, CultureInfo.CurrentUICulture)
        {
        }
    }
    

    View

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<MyViewModel>
    
    @{
        Layout = "_header.cshtml";
    }
    
    @Html.Raw(umbraco.library.RenderMacroContent(Model.Content.GetPropertyValue<string>("pageMacros"), Model.Content.Id))
    

    It's failing on Model.Content.GetPropertyValue(), but only when I use a query string. I hoped creating a custom route would trick it into working, but that presented the same error too.

    If anyone can shed any light on this issue appreciate it!

    I've tried removing everything from the MyPage() function, but it still fails. I've even tried just passing Umbraco.TypedContentAtRoot().First() to the model, and that fails also with the query string.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 21, 2015 @ 21:04
    Alex Skrypnyk
    0

    Hi Daniel,

    Can you show code of your macro partial view ?

  • Daniel Chenery 119 posts 465 karma points
    Sep 22, 2015 @ 07:37
    Daniel Chenery
    0

    Hi Alex,

    Thanks for the reply.

    Please find the code below. This issue will still occur if I empty this file though, or just put the word "TEST" in there.

    Macro Partial View

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
        var utility = new MyWebUtility();
    
        if (!utility.isUmbracoNull(Model.MacroParameters["blockHyperlink"].ToString())
            && (utility.isUmbracoNull(Model.MacroParameters["blockButtonText"].ToString())))
        {
            <a href="@Model.MacroParameters["blockHyperlink"]" class="@Model.MacroParameters["blockWidth"]">
                @renderblockContent()
            </a>
        }
        else
        {
            <div class="@Model.MacroParameters["blockWidth"]">
                @renderblockContent()
            </div>
        }
    }
    
    @helper renderblockContent() {
    
        var utility = MyWebUtility();
        var m = MediaHelper.ParseMedia(@Model.MacroParameters["blockImage"].ToString(), Umbraco, "blockImage");
    
        <img src="@m.Url" alt="@Model.MacroParameters["blockHeading"]" />
    
        if (Model.MacroParameters["blockHeadingPosition"].ToString() == Model.MacroParameters["blockCaptionPosition"].ToString())
        {
            if (!utility.isUmbracoNull(Model.MacroParameters["blockHeading"].ToString()))
            {
                <div class="caption @Model.MacroParameters["blockHeadingPosition"] @Model.MacroParameters["blockHeadingSize"]">
                    <h3>@Model.MacroParameters["blockHeading"]</h3>
                    <p>@Model.MacroParameters["blockCaption"]</p>
                </div>
            }
        }
        else
        {
            if (!utility.isUmbracoNull(Model.MacroParameters["blockHeading"].ToString()))
            {
                <div class="caption @Model.MacroParameters["blockHeadingPosition"] @Model.MacroParameters["blockHeadingSize"]">
                    <h3>@Model.MacroParameters["blockHeading"]</h3>
                </div>
            }
            if (!utility.isUmbracoNull(Model.MacroParameters["blockCaption"].ToString()))
            {
                <div class="caption @Model.MacroParameters["blockCaptionPosition"] @Model.MacroParameters["blockCaptionSize"]">
                    <p>@Model.MacroParameters["blockCaption"]</p>
                </div>
            }
        }
    
        if (!utility.isUmbracoNull(Model.MacroParameters["blockButtonText"].ToString()))
        {
            <a href="@Model.MacroParameters["blockHyperlink"]" class="purple-btn">@Model.MacroParameters["blockButtonText"]</a>
        }
    }
    

    I've also the following error in my logs:

    2015-09-22 08:35:57,908 [51] WARN umbraco.macro - [P15912/T1/D15] Error loading Partial View (file: ~/Views/MacroPartials/Block.cshtml). Exception: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

    The remainder of the page also fails to load any other (non-macro) partials once I hit this error. I just don't understand why it's only the query string which causes this problem - no matter what I rename it to.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 22, 2015 @ 09:14
    Alex Skrypnyk
    0

    Daniel,

    Try to use Umbraco helper class for rendering macro -

    Umbraco.RenderMacro("alias")
    

    Thanks,

    Alex

  • Daniel Chenery 119 posts 465 karma points
    Sep 22, 2015 @ 09:31
    Daniel Chenery
    0

    Hi Alex,

    I've just tried that - I'm using a Data Type where a user can select from a number of Macros, so I'm not sure how this works with those.

    But even if I put the alias of the Macro currently selected in I still get the same error of "Error loading..." etc.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 22, 2015 @ 09:48
    Alex Skrypnyk
    0

    Daniel,

    So problem not with Umbraco methods, something with alias or path to your view. Can you check maybe folder restrictions ? Can your application access to the folder with macro view ?

    Thanks,

    Alex

  • Daniel Chenery 119 posts 465 karma points
    Sep 22, 2015 @ 10:04
    Daniel Chenery
    0

    Hi Alex,

    The path it's throwing an error to is correct, and like I say, it works without the query string. I've given "Everyone" full permission, still the same issue unfortunately :(

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 22, 2015 @ 10:56
    Alex Skrypnyk
    0

    Did you check Umbraco log ?

  • Daniel Chenery 119 posts 465 karma points
    Sep 22, 2015 @ 11:00
    Daniel Chenery
    0

    I did, as mentioned earlier :)

    The following message:

    2015-09-22 11:26:13,993 [21] WARN umbraco.macro - [P12804/T27/D5] Error loading Partial View (file: ~/Views/MacroPartials/Block.cshtml). Exception: System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext() at System.Web.Mvc.ModelStateDictionary.Merge(ModelStateDictionary dictionary) at Umbraco.Web.Mvc.ControllerExtensions.EnsureViewObjectDataOnResult(ControllerBase controller, ViewResultBase result) at Umbraco.Web.Mvc.ControllerExtensions.RenderViewResultAsString(ControllerBase controller, ViewResultBase viewResult) at Umbraco.Web.Macros.PartialViewMacroEngine.Execute(MacroModel macro, IPublishedContent content) at Umbraco.Web.Macros.PartialViewMacroEngine.Execute(MacroModel macro, INode node) at umbraco.macro.LoadPartialViewMacro(MacroModel macro) at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 22, 2015 @ 11:21
    Alex Skrypnyk
    0

    Daniel, maybe something with isUmbracoNull method ? Can you check MyWebUtility class also ? Can you debug ?

    Thanks

  • Daniel Chenery 119 posts 465 karma points
    Sep 22, 2015 @ 13:01
    Daniel Chenery
    0

    Hi Alex,

    Running in debug mode unfortunately throws no errors.

    The contents of isUmbracoNull() is this:

    public bool isUmbracoNull(string input)
    {
        // made to override a bug in umbraco that sets empty fields to a string of "null"
        if (input == null || input == String.Empty || input == "null")
            return true;
        else
            return false;
    }
    

    The function wasn't hit at all when loading the page with the error

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 22, 2015 @ 13:19
    Alex Skrypnyk
    100

    Looks like I found the solution - http://issues.umbraco.org/issue/U4-6721

    It's known problem.

    About - isUmbracoNull

    You don't need this method at all, try to replace it with string.IsNullOrEmpty()

    Thanks,

    Alex

  • Daniel Chenery 119 posts 465 karma points
    Sep 22, 2015 @ 13:24
    Daniel Chenery
    0

    Well that'll stop me scratching my head as to why it wasn't working! Hopefully 7.3 will be shipped soon.

    Thanks! :)

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 22, 2015 @ 13:29
    Alex Skrypnyk
    0

    Yes, we are using 7.3.-RC by the way.

    Thanks,

    Alex

    https://ua.linkedin.com/pub/alexander-skripnik/66/60b/352

Please Sign in or register to post replies

Write your reply to:

Draft