Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Messing around with ModelsBuilder, I have been converting some old style CurrentPage views.
While I was at it I decided to derive my views from UmbracoViewPage<MyNiceModel>
The doctype for MyNiceModel contains a grid property called Content (a bit confusingly maybe) so I tried:
That gives me a 'deprecated' warning though:
I therefore went with:
@Html.GetGridHtml(Model, "content", "mygridpartial")
However, that seems less elegant given that I now have to provide the Model property as a string value (so there goes one of the benefits of strongly typed models?).
To avoid confusion due to my poor choice of doctype property names and to increase educational value :) this is the problem:
My Doctype has a property that is a grid, call it MyGridProperty
There are two ways to get at it in templates (i.e. views) when using ModelsBuilder:
@using ContentModels = Umbraco.Web.PublishedContentModels;
or if you go the route that V8 will ultimately go:
In both cases however, MyGridProperty will return as type Newtonsoft.Json.Linq.JToken because of course, grid content is stored as JSON.
That causes a problem in the sense that none of the overloads for @Html.GetGridHtml() take arguments other than IPublishedContent or alias strings as you can see here
I can somehow understand why that it is so but then again a call like:
@Html.GetGridHtml(Model, "MyGridProperty", "MyGridPartial")
Takes away some of the advantages of strong typing (because you refer to the property in string form).
Should the Grid related extension methods not be able to handle JToken arguments directly?
Can't you do: @Html.GetGridHtml(Model.Content.GridProperty, "mygridpartial") ?
I am using UmbracoViewPage for the template (the one that will be the new standard in v8) so you can omit the Content property of model and instead call @Model.someproperty.
However, my property is called Content (hence my calling it confusing). I edited the original post so that is clarified a bit.
As such, I cannot seem to call what you suggest, I.e. @Html.GetGridHtml(Model.someproperty, "some partial alias") because there are no overloads of GetGridHtml that take anything other than IPublishedContent as arguments...
@Html.GetGridHtml(Model.someproperty, "some partial alias")
Hmm, I have to look into that. I know I had something similar in a project.
I tried several ways but no luck. We use @Html.GetGridHtml(IPublishedContent, "propertyÄlias", "partialAlias")
It seems to be the only way.
@Html.GetGridHtml(IPublishedContent, "propertyÄlias", "partialAlias")
It would be nice if we could have a @html.GetGridHtml(Model.Property, "partialAlias")
No worries, thanks for following up though.
If you look at the source there is indeed no other way.
Probably the Html extensions need to be amended with one that can handle the JSON or the model should return something else than it is doing now. I guess only HQ knows how they will go about it :)
Lol, Why are we awake :P
But true. It is something that's overlooked since the implementation of modelsbuilder I think
Haha, I am actually working from North America for a while so for me the hour is still reasonable, but I know the feeling: digging into the inner workings of Umbraco can keep you awake :)
I just tripped across this very need. Trying to do everything using strongly typed models and this is a bit of a fly in the ointment.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted