Need help with visual studio and mvc razor and getting a property value
I am struggling with this MVC/Razor thing again. So I installad a site using WebMatrix and also installed VS Web 2013. In WebMAtrix I press the VS button to start my coding, hoping for some intellisene etc.
I want to loop through a node that contains children. Each child is an item for in a carrousel slider. So now I created a MVC Partial Macro for this.
In the foreach i want to check if the current child (page) has a value for sliderLink (contentPicker).
1. I cannot get intellisense (see picture). Is this normal? Or do i need to change something.
2. How can i check if a page was picked. Model.Content.HasValue does only contain properties of the currentpage (if i'm correct).
Dynamic objects are just that - dynamic. Meaning that they can be just about anything you want. That is why you don't get any intellisense (what is it supposed to 'sense' when it can be anything?).
Instead of 'Umbraco.Content(id)' use 'Umbraco.TypedContent(id)' - that way, intellisense will know what object type you are using.
So, i used to have @page.sliderCaption (which is a textbox custom property). But now i have changed accordingly, @page.sliderCaption does not work anymore and I have to use page.GetPropertyValue("sliderCaption"). Why is that?
Dynamics is concise in that you can do CurrentPage.propertyName but Strongly Typed gives you intellisense but you cannot use dynamic property names.
Something you could consider is the Zbu.ModelsBuilder package which generates strongly typed models from your document types meaning you can do Model.Content.PropertyName and have Intellisense!
Need help with visual studio and mvc razor and getting a property value
I am struggling with this MVC/Razor thing again. So I installad a site using WebMatrix and also installed VS Web 2013. In WebMAtrix I press the VS button to start my coding, hoping for some intellisene etc.
I want to loop through a node that contains children. Each child is an item for in a carrousel slider. So now I created a MVC Partial Macro for this.
In the foreach i want to check if the current child (page) has a value for sliderLink (contentPicker).
1. I cannot get intellisense (see picture). Is this normal? Or do i need to change something.
2. How can i check if a page was picked. Model.Content.HasValue does only contain properties of the currentpage (if i'm correct).
hope somebody can help me with this
Switch to Umbraco.TypedContent and then it will work. Also you should use Umbraco.TypedMedia, Umbraco.TypedMember etc
Dynamic objects are just that - dynamic. Meaning that they can be just about anything you want. That is why you don't get any intellisense (what is it supposed to 'sense' when it can be anything?).
Instead of 'Umbraco.Content(id)' use 'Umbraco.TypedContent(id)' - that way, intellisense will know what object type you are using.
Hope that answers your question :)
Where do i do this switch?
Change
Into
That will give you full intellisense on that object.
You have
var startNode = Umbraco.Content(startNodeID);
change tovar startNode = Umbraco.TypedContent(startNodeID);
Thanks.
So, i used to have @page.sliderCaption (which is a textbox custom property). But now i have changed accordingly, @page.sliderCaption does not work anymore and I have to use page.GetPropertyValue("sliderCaption"). Why is that?
That is dynamics vs strongly typed.
Dynamics is concise in that you can do
CurrentPage.propertyName
but Strongly Typed gives you intellisense but you cannot use dynamic property names.Something you could consider is the Zbu.ModelsBuilder package which generates strongly typed models from your document types meaning you can do
Model.Content.PropertyName
and have Intellisense!There is a video demo of using it here
Getting there :-)
So would this be a correct way of coding this, or am i taking some unneeded detours?
Generally pretty good, I have made a few minor tweaks below:
is working on a reply...