Model in cshtml incorrectly referring to the current Page
In my Content (in Umbraco) I have
A "page" for showing all News
A "folder" containing NewsItem's (NewsItem has a property called Teaser)
In the page, I have this code
var allNews = new Node(Static.NODE_ID_NEWS).Children; foreach (INode newsItem in allNews) { string teaserText = umbraco.library.RenderMacroContent(newsItem.GetProperty("teaser").Value, newsItem.Id);
That renders the following macro (cshtml)
name = @Model.Name <br /> id = @Model.Id
From that, I found out that, when run from the page (ie. frontend), the Model is the page, not the news item. (When previewed from TinyMce editor it correctly showed the NewsItem name and ID)
How can I get the actual news item from this .cshtml file? (I'm also happy to use usercontrol for the macro)
Unfortunately, I don't think I can be of much more help anymore :-S Just one last question: when you say "In the page, I have this code", what do you mean exactly?. Is it in the template? Or in some user control?
I am trying to pull off same trick. I have macro string (<?UMBRACO_MACRO macroAlias="MyMacroAlias" />) as property value on a node (alias "submenuMacroContent").
I found the same problem in our current development. I was providing a different nodeId than current page, but the macro was always getting Model.ID = current page, not the one I had provided.
After diving a while through the source code, I found this workaround: modifying directly Context.Current.Items["pageID"].
NOTE: I'm not sure about the implications of this in different scenarios. What I know is that in my case is working fine.
Model in cshtml incorrectly referring to the current Page
In my Content (in Umbraco) I have
(NewsItem has a property called Teaser)
In the page, I have this code
That renders the following macro (cshtml)
From that, I found out that, when run from the page (ie. frontend), the Model is the page, not the news item. (When previewed from TinyMce editor it correctly showed the NewsItem name and ID)
How can I get the actual news item from this .cshtml file?
(I'm also happy to use usercontrol for the macro)
Thank you in advance.
Hi Hardi,
Not sure it will help a lot, but have you tried with @DynamicModel instead of @Model?
Cheers,
Michael.
"DynamicModel does not exist in the current context" it says... Thanks anyway :) I'm giving up soon
Hi Hardi,
Unfortunately, I don't think I can be of much more help anymore :-S Just one last question: when you say "In the page, I have this code", what do you mean exactly?. Is it in the template? Or in some user control?
Cheers,
Michael.
Sorry, by page I mean the master page (ie. the template, which shows as xxx.aspx on the frontend). Can't edit the question in this forum.
That's ok, I'm not using macros anymore, and you've helped a lot! =) Thanks again!
OK, too bad it did not work with macro's, but if you got it working in some other way, it's already something :-)
Cheers,
Michael.
Hi,
I am trying to pull off same trick. I have macro string (<?UMBRACO_MACRO macroAlias="MyMacroAlias" />) as property value on a node (alias "submenuMacroContent").
That macro gets rendered in incorrect context. I want it to be rendered in child.Id context but it renders as in Model.Id.
Maybe its bug?
Hi,
I found the same problem in our current development. I was providing a different nodeId than current page, but the macro was always getting Model.ID = current page, not the one I had provided.
After diving a while through the source code, I found this workaround: modifying directly Context.Current.Items["pageID"].
NOTE: I'm not sure about the implications of this in different scenarios. What I know is that in my case is working fine.
I see this post is quite old, but the problem remains unsolved.
Hope this helps,
Jonatan
is working on a reply...