For a partial that gets child pages, I wrote a if{elseif{else in a foreach loop that checks for images, and it works well so I'd like to make it a partial and reuse it in other, similar partials. I haven't been able to find a good doc or example to get me started, mostly the v.7 docs seem to be about parameters in macros.
I think it could be as simple as: @Html.Partial("imageCheck", childPage), childPage being the var from the foreach loop, and then something like a var childPage = ViewData["childPage"];but that doesn't seem to bring the childPage data along.
I did read that, quite a few times, but it is still at too high a level for me. For instance, under Strongly Typed PV's, it says, you just need to do this: @inherits Umbraco.Web.Mvc.UmbracoViewPage<MyModel> but I can't figure out what <MyModel> represents. Elsewhere in life, those <> indicate a replaceable value but in some places in Umbraco, the <> are required. Regardless, I've not found a combination either way that makes it past intellisense.
Later, it says if you are passing around instances if IPublishedContent, just inherit from Umbraco.Web.Mvc.UmbracoTemplatePage, with @Html.Partial(MyPartialName", child) but doesn't say how to use that in the partial. So far, my efforts there have not gotten past intellisense either, maybe because I don't know what to do with that first <MyModel>.
I've also tried variations on the Getting Started docs, which include promising bits similar to what I've seen in Kevin's LocalGov package:
@Html.Partial("YourPartialName", new ViewDataDictionary{{ "age",33},{"name","peter"}})
retrieved with ViewData["age"]but again, no love for me, 'the name 'age' does not exist in the current context', etc.
I looked at the 'Pass Additional ViewData to an ASP.NET MVC 4 Partial... doc as well but that looks like the wrong way is what everything else suggests is the right way, I don't think I can make sense of it from where I'm at.
Also watched the vid linked in the first docs referenced, How Do I Work with Data in ASP.NET MVC PV's, but that was from 2009 and 15 of its 20 minutes were watching him type model data, I fell asleep twice. It is also a concern that old information like that is likely to include some syntactical obsolescence that will devour another half a day of ignorant disenlightenment.
I know I'm weak on what are probably fundamentals for what I'm trying to do but it seems so close...
Thanks for trying though, I appreciate your taking the time. If you have a recommendation for a good book on the subject (ASP.NET, I assume), I'd be glad to purchase it. I perused a few and didn't find anything that looked like it would have the answer to sending my 'childPage' to a little 'if' filter.
So the value 'totallyrandom' is coming over fine in 'randomVar' and the value of 'uPage' appears to match up as well.
However, if I change the second partial's '@someVar' to '@someVar.Name', intellisense says 'Cannot convert method group...', so all is not well. Other variations have also gone down in flames.
I'm guessing it has to do with the value coming over as a string but no clue where to go next. Any idea?
Passing parameters from one partial to another
For a partial that gets child pages, I wrote a if{elseif{else in a foreach loop that checks for images, and it works well so I'd like to make it a partial and reuse it in other, similar partials. I haven't been able to find a good doc or example to get me started, mostly the v.7 docs seem to be about parameters in macros.
I think it could be as simple as:
@Html.Partial("imageCheck", childPage)
, childPage being the var from the foreach loop, and then something like avar childPage = ViewData["childPage"];
but that doesn't seem to bring the childPage data along.Any tips, pointers, good jokes, whatever?
Thanks much.
Hello,
Did you read the documentation?
Maybe this can also help: http://www.codenoevil.com/pass-additional-viewdata-asp-net-mvc-4/
Jeroen
Hi,
I did read that, quite a few times, but it is still at too high a level for me. For instance, under Strongly Typed PV's, it says, you just need to do this: @inherits
Umbraco.Web.Mvc.UmbracoViewPage<MyModel>
but I can't figure out what<MyModel>
represents. Elsewhere in life, those<>
indicate a replaceable value but in some places in Umbraco, the<>
are required. Regardless, I've not found a combination either way that makes it past intellisense.Later, it says if you are passing around instances if IPublishedContent, just inherit from Umbraco.Web.Mvc.UmbracoTemplatePage, with
@Html.Partial(MyPartialName", child)
but doesn't say how to use that in the partial. So far, my efforts there have not gotten past intellisense either, maybe because I don't know what to do with that first<MyModel>
.I've also tried variations on the Getting Started docs, which include promising bits similar to what I've seen in Kevin's LocalGov package:
retrieved with
ViewData["age"]
but again, no love for me, 'the name 'age' does not exist in the current context', etc.I looked at the 'Pass Additional ViewData to an ASP.NET MVC 4 Partial... doc as well but that looks like the wrong way is what everything else suggests is the right way, I don't think I can make sense of it from where I'm at.
Also watched the vid linked in the first docs referenced, How Do I Work with Data in ASP.NET MVC PV's, but that was from 2009 and 15 of its 20 minutes were watching him type model data, I fell asleep twice. It is also a concern that old information like that is likely to include some syntactical obsolescence that will devour another half a day of ignorant disenlightenment.
I know I'm weak on what are probably fundamentals for what I'm trying to do but it seems so close...
Thanks for trying though, I appreciate your taking the time. If you have a recommendation for a good book on the subject (ASP.NET, I assume), I'd be glad to purchase it. I perused a few and didn't find anything that looked like it would have the answer to sending my 'childPage' to a little 'if' filter.
So, I have this in the first partial:
then in the uImage partial, this:
and it renders this in the browser:
Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedContent.
totallyrandom
So the value 'totallyrandom' is coming over fine in 'randomVar' and the value of 'uPage' appears to match up as well.
However, if I change the second partial's '@someVar' to '@someVar.Name', intellisense says 'Cannot convert method group...', so all is not well. Other variations have also gone down in flames.
I'm guessing it has to do with the value coming over as a string but no clue where to go next. Any idea?
Holy crapnoodles, I think I figgered it oot:
In partial 1:
In partial 2:
So far it seems to be rendering properly. Anything wrong with that?
Hi Matthew, how are you checking if childPage.Id is null? I can't seem to find a way to make sure it actually contains something?
Thanks,
Amir
is working on a reply...