Your picker (assuming you've configured it to store in CSV format) will contain a comma delimited set of node IDs. In your controller you can turn them into nodes by splitting on the string to get an array of integers, and using the Umbraco helper's TypedContent method to get back an IEnumerable<IPublishedContent>. From there, they are nodes just like CurrentPage, so you can work with them in the same way.
I'd also suggest looking at the core property converters package. WIth that installed you can get back a IEnumerable<IPublishedContent> without all the faffing around with strings and arrays.
Jepp, got that far, got the IPublishedContent from the node id but how do i return the content from my controller?
My structure is as follows, just an example.
- DocumentType
- - About
- Template
- - About
public class AboutController : RenderMvcController
{
public ActionResult About()
{
var something = Umbraco.TypedContent(1111);
<code>?????????</code>
return View(????????);
}
}
Given you are hijacking routes, you could here create a custom view model (a simple POCO class), map the appropriate fields from your content, and return that to the view. That would be the more MVC way to do things.
There are alternative though if you prefer other approaches. You could use the ViewBag and put the content in there, so it will be available to your view. Or even put the Umbraco.TypedContent call in your view rather than in your controller, and avoid route hijacking all together, and get the related content there.
My full approach is that all my views are strongly typed, and all the view models inherits from a base model.
On each request a model is filled with page specific data, the base controller than completes the model with base data, navigation, meta, and returns as base.View(model).
All according to MVC :)
My issue here is that i don´t know how to get which view to return and with what data, the about page is somewhere else in the node hierarchy and the child page only holds the id to that page.
Feeling quite dumb here... Been working with MVC for the last 5 or 6 years but cant get an simple return to function :(
Reuse node/page
Hi,
What is the best way of reusing a node/page?
I can for example copy the node and tick the relation box, the parent and child relation saves.
As the parent node changes i catch the
ContentService.Saved
event and updates the child node with new values.The downside with this approach is that the child node does not tell that it has an relation and i have to keep duplicates of the content.
Tried to create a new document type with one property, picker to parent node, but i dont know how to return this content from my controller.
Would love some input.
By the way, i´m using Umbraco 7.
//Robert
Hi Robert
Your picker (assuming you've configured it to store in CSV format) will contain a comma delimited set of node IDs. In your controller you can turn them into nodes by splitting on the string to get an array of integers, and using the Umbraco helper's TypedContent method to get back an IEnumerable<IPublishedContent>. From there, they are nodes just like CurrentPage, so you can work with them in the same way.
I'd also suggest looking at the core property converters package. WIth that installed you can get back a IEnumerable<IPublishedContent> without all the faffing around with strings and arrays.
Hope that helps.
Andy
Hi Andy and thanks for your reply.
Jepp, got that far, got the IPublishedContent from the node id but how do i return the content from my controller?
My structure is as follows, just an example.
Given you are hijacking routes, you could here create a custom view model (a simple POCO class), map the appropriate fields from your content, and return that to the view. That would be the more MVC way to do things.
There are alternative though if you prefer other approaches. You could use the ViewBag and put the content in there, so it will be available to your view. Or even put the Umbraco.TypedContent call in your view rather than in your controller, and avoid route hijacking all together, and get the related content there.
The above was a little to basic example :)
My full approach is that all my views are strongly typed, and all the view models inherits from a base model.
On each request a model is filled with page specific data, the base controller than completes the model with base data, navigation, meta, and returns as
base.View(model)
.All according to MVC :)
My issue here is that i don´t know how to get which view to return and with what data, the about page is somewhere else in the node hierarchy and the child page only holds the id to that page.
Feeling quite dumb here... Been working with MVC for the last 5 or 6 years but cant get an simple return to function :(
Did a go with
PublishedContentRequest.Prepared
in order to replace the content with content from node id, a longshot which did not work.Would be nice if i could trigger my controller/action based on node id.
Post my solution if someone else need some input, quick...
Solved this by creating a new
IContentFinder
, implementingContentFinderByNiceUrl
.If content type is of specified type i just replace
PublishedContent
with new content from requested node id.is working on a reply...