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:
[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)
{
}
}
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.
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.
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 ?
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 :(
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)
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
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:
And here are some code snippets to help you out.
Controller
Model
View
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.
Hi Daniel,
Can you show code of your macro partial view ?
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
I've also the following error in my logs:
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.
Daniel,
Try to use Umbraco helper class for rendering macro -
Thanks,
Alex
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.
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
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 :(
Did you check Umbraco log ?
I did, as mentioned earlier :)
The following message:
Daniel, maybe something with isUmbracoNull method ? Can you check MyWebUtility class also ? Can you debug ?
Thanks
Hi Alex,
Running in debug mode unfortunately throws no errors.
The contents of isUmbracoNull() is this:
The function wasn't hit at all when loading the page with the error
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
Well that'll stop me scratching my head as to why it wasn't working! Hopefully 7.3 will be shipped soon.
Thanks! :)
Yes, we are using 7.3.-RC by the way.
Thanks,
Alex
https://ua.linkedin.com/pub/alexander-skripnik/66/60b/352
is working on a reply...