Sure, you can use Ditto the same way within your controller code...
public override ActionResult Index(RenderModel model)
{
var poco = model.Content.As<MyTextPage>();
// do something with your POCO
// poco.Title
return CurrentTemplate(poco);
}
Thanks Lee for the reply. And sorry for the late reply.
My question is that.
1) Is it compulsory to use (RenderModel model) as parameters?
2) Can we have pre defined valued which we have filled in the content page in that var poco.
For eg, I have created 3 property bodyText , title , image.
And created one content page of that document type and filled all the value.
So , can we get that values like poco.title , poco.bodyText , poco.image in the controller ?
And also we need to create that properties in our MyTextPage class? or it will take automatic properties ?
1) Is it compulsory to use (RenderModel model) as parameters?
It's not compulsory if you are using your own MVC controllers, (outside of Umbraco), but if you are making use of "route hijacking" then yes it will have the RenderModel parameter. See this documentation section for "Custom controllers" for more info:
2) Can we have pre defined valued which we have filled in the content page in that var poco
I'm not sure what you mean by "pre defined valued"? But with the POCO itself, yes you'll need to add those properties to your MyTextPage class, e.g.
public class MyTextPage
{
public string Title { get; set; }
public HtmlString BodyText { get; set; }
public int Image { get; set; }
}
Note: With the Image property, by default it would be an int, but there are more advanced ways to map a media item to a POCO directly - but I think that's for a separate (follow-up) post.
I'd need to see some of your code if I can help to spot any issues.
Maybe take a watch of the uHangout video I did about Ditto - here's a link to about 20 mins into the video where I show the demo: https://youtu.be/L40haIBLNS4?t=1040
my question is how to use var poco = model.Content.As<MyTextPage>(); without using RenderModel and RendeMvcController
public class myController : Controller // <- this is possible or not? or always use RendeMvcController ?
{
public override ActionResult Index() // <- below code is possible without RenderModel ?
{
var poco = model.Content.As<MyTextPage>();
return CurrentTemplate(poco);
}
}
With the given routes, what content are you expecting to get in "/TestNews"?
Does this URL correspond with a node in Umbraco? If not, then you can use the UmbracoHelper (RenderMvcController has it as a property called Umbraco) ... so you can use any of the helper methods to get the node.
How to get property value using Ditto in Controller without using MVC Render control
Hi,
I am using Umbraco 7.2.2.
How to get property value using Ditto in Controller without using MVC Render control?
I have made one class with document type property alias.
As mentioned we are able to get property in View like below.
But at the same time we are not able to get that value from the controller.
Can any one help?
Thanks in advance.
Regards,
Urvish Mandaliya
Hi Urvish,
Sure, you can use Ditto the same way within your controller code...
Cheers,
- Lee
Thanks Lee for the reply. And sorry for the late reply.
My question is that.
1) Is it compulsory to use (RenderModel model) as parameters?
2) Can we have pre defined valued which we have filled in the content page in that var poco.
For eg, I have created 3 property bodyText , title , image. And created one content page of that document type and filled all the value. So , can we get that values like poco.title , poco.bodyText , poco.image in the controller ?
And also we need to create that properties in our MyTextPage class? or it will take automatic properties ?
Regards,
Urvish Mandaliya
Hi Urvish,
It's not compulsory if you are using your own MVC controllers, (outside of Umbraco), but if you are making use of "route hijacking" then yes it will have the
RenderModel
parameter. See this documentation section for "Custom controllers" for more info:https://our.umbraco.org/documentation/Reference/Mvc/custom-controllers
I'm not sure what you mean by "pre defined valued"? But with the POCO itself, yes you'll need to add those properties to your
MyTextPage
class, e.g.Note: With the
Image
property, by default it would be anint
, but there are more advanced ways to map a media item to a POCO directly - but I think that's for a separate (follow-up) post.I hope this helps?
Cheers,
- Lee
Thanks Lee for the reply.
Yes it helps a lot.
"pre defined valued" means the values which I have entered in content page.
So can I get that value of title 'Test' and other value like this. poco.title = "Test" , poco.bodyText ="" etc.
Regards,
Urvish Mandaliya
Hi Urvish,
Yes, absolutely - the values from the content node will populate the POCO properties. (That's the entire goal of Ditto!)
Cheers,
- Lee
Thanks a lot Lee for your support.
I appreciate your help and support.
I need to check from my self that what I am missing? Because I am not getting values from that poco properties.
Thanks again.:)
Regards,
Urvish Mandaliya
I'd need to see some of your code if I can help to spot any issues.
Maybe take a watch of the uHangout video I did about Ditto - here's a link to about 20 mins into the video where I show the demo:
https://youtu.be/L40haIBLNS4?t=1040
Cheers,
- Lee
ok thanks Lee.
Sure will let you know if I stuck up while implementing this.
Regards,
Urvish Mandaliya
Hi Lee,
my question is how to use
var poco = model.Content.As<MyTextPage>();
without usingRenderModel
andRendeMvcController
Kindly advice on this
Thanks in advance
Regards,
Mehul Gajjar.
Hi Mehul,
This question isn't really about Ditto, it's about how to access content within your own MVC controller.
Is there a reason why you can't inherit from
UmbracoController
?Thanks,
- Lee
Hi Lee, Thanks for prompt reply ,
i have now inherit control with RenderMvcController. and its working fine.
but facing issue while i have set custom routing.
Problem : Render model get null in controller via custom routing . see below.
1) below is my star up handler
2) controller
case 1) When i visit the page using this url
http://localhost:63247/new
i got value in RenderModelcase 2) When i visit the page using this url
http://localhost:63247/TestNews
i got Null value in RenderModelplease give some suggestion how to get value in RenderModel in case 2 using custom route.
Thanks for your help.
Regards
Mehul.
Hi Mehul,
With the given routes, what content are you expecting to get in "/TestNews"?
Does this URL correspond with a node in Umbraco? If not, then you can use the
UmbracoHelper
(RenderMvcController
has it as a property calledUmbraco
) ... so you can use any of the helper methods to get the node.e.g.
Hi Lee ,
Many Thanks for reply
I will try with above
Regards,
Mehul.
is working on a reply...