New to Razor and Umbraco, Many Many problems with @Model not working.
Hi Everyone,
I've spent the better part of the entire day attempting to understand razor and umbraco and every issue I run into seems to be surrounding any line that uses "Model".
I am attempting to parse through a list of MultiNode Treepicker things. Doing a simple @homePage.clientList shows that my clientList multinode treepicker has a few things inside of it.
I am attempting to parse through the list using an example I found,
@foreach(var item in Model.refKursus) {
var node = @Model.NodeById(item.InnerText);
So I have a handful of questions about this. First of all, what would replace refKursus? I get this error, which I expect since refKursus doesn't seem like anything real. Compiler Error Message: CS1061: 'Umbraco.Web.Models.RenderModel' does not contain a definition for 'refKursus' and no extension method 'refKursus' accepting a first argument of type 'Umbraco.Web.Models.RenderModel' could be found (are you missing a using directive or an assembly reference?)
Secondly, if I remove the loop all together, find my own node id, and do a simple var node = Model.NodeById(1120), I get one of these bad boys. Compiler Error Message: CS1061: 'Umbraco.Web.Models.RenderModel' does not contain a definition for 'NodeById' and no extension method 'NodeById' accepting a first argument of type 'Umbraco.Web.Models.RenderModel' could be found (are you missing a using directive or an assembly reference?)
I have been getting so many different errors surrounding this "Umbraco.Web.Models.RenderModel" so I have to have not set it up correctly. Can someone please help me with this? This is pretty much the last thing holding me down. Let me know if you need more information.
Since you are using Umbraco 7, then you can use two types of razor dynamic razor or strongly typed razor. For getting currentpage in dynamic razor you need to use
@CurrentPage
If you are using strongly typed razor you get the currentpage like this:
Well after reading that it certainly cut down on a large majority of my errors. Thank you very much!
The only issue left seems to be a regular error of me just not knowing enough about Razor.
@{
var clientList = CurrentPage.clientList.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
var clientCollection = Umbraco.Content(clientList);
foreach (var item in clientCollection)
{
<p>@item.Name</p>
}
}
This now works beautifully. However, my contentpicker has a property which is a second content picker. When I call say item.clienttestimonial which is my second content picker, I get the node id. I'm thinking I'd need to create a variable of a node with that given node id, then I would be able to use both original multinode treepicker, as well as the connected one. How would I go about specifying that second node variable? Just using something simple like var testimonial = item.clienttestimonial just gives me an integer variable of the node's number.
New to Razor and Umbraco, Many Many problems with @Model not working.
Hi Everyone,
I've spent the better part of the entire day attempting to understand razor and umbraco and every issue I run into seems to be surrounding any line that uses "Model".
I am attempting to parse through a list of MultiNode Treepicker things. Doing a simple @homePage.clientList shows that my clientList multinode treepicker has a few things inside of it.
I am attempting to parse through the list using an example I found,
@foreach(var item in Model.refKursus) {
var node = @Model.NodeById(item.InnerText);
So I have a handful of questions about this. First of all, what would replace refKursus?
I get this error, which I expect since refKursus doesn't seem like anything real.
Compiler Error Message: CS1061: 'Umbraco.Web.Models.RenderModel' does not contain a definition for 'refKursus' and no extension method 'refKursus' accepting a first argument of type 'Umbraco.Web.Models.RenderModel' could be found (are you missing a using directive or an assembly reference?)
Secondly, if I remove the loop all together, find my own node id, and do a simple var node = Model.NodeById(1120), I get one of these bad boys.
Compiler Error Message: CS1061: 'Umbraco.Web.Models.RenderModel' does not contain a definition for 'NodeById' and no extension method 'NodeById' accepting a first argument of type 'Umbraco.Web.Models.RenderModel' could be found (are you missing a using directive or an assembly reference?)
I have been getting so many different errors surrounding this "Umbraco.Web.Models.RenderModel" so I have to have not set it up correctly. Can someone please help me with this? This is pretty much the last thing holding me down. Let me know if you need more information.
I am using Umbraco 7 by the way.
Hi Brian,
Since you are using Umbraco 7, then you can use two types of razor dynamic razor or strongly typed razor. For getting currentpage in dynamic razor you need to use
If you are using strongly typed razor you get the currentpage like this:
Try to see this documentation for using the Multi-Node-Tree-Picker in Umbraco 7. http://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/Built-in-Property-Editors-v7/Multinode-Treepicker
And here are some documentation on the differnce between the old DynamicNode Razor and Dynamic Razor and Strongly Typed razor,
http://our.umbraco.org/documentation/Reference/Mvc/partial-views
http://our.umbraco.org/documentation/Reference/Mvc/views
http://our.umbraco.org/documentation/reference/templating/macros/Partial-View-Macros/
Hope this helps,
/Dennis
Well after reading that it certainly cut down on a large majority of my errors. Thank you very much!
The only issue left seems to be a regular error of me just not knowing enough about Razor.
@{
var clientList = CurrentPage.clientList.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
var clientCollection = Umbraco.Content(clientList);
foreach (var item in clientCollection)
{
<p>@item.Name</p>
}
}
This now works beautifully. However, my contentpicker has a property which is a second content picker. When I call say item.clienttestimonial which is my second content picker, I get the node id. I'm thinking I'd need to create a variable of a node with that given node id, then I would be able to use both original multinode treepicker, as well as the connected one. How would I go about specifying that second node variable? Just using something simple like var testimonial = item.clienttestimonial just gives me an integer variable of the node's number.
Hi Brian,
Good to hear that the most of the errors are gone now.
Yes I think that you need to make a variable what if you are doing something like this.
The documentation for the content picker can you find here.http://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/Built-in-Property-Editors-v7/Content-Picker
Hope this helps,
/Dennis
is working on a reply...