You can access Vorto values the same way as you would do in your view. IPublishedContent (which is what you're using in your views) is also what you should be using in your controllers:
var value = Umbraco.TypedContent(1).GetVortoValue("alias", "cultureName");
Thanks very much!
So you mean that we have to use strongly typed content to get the values.
but, is it necessary to add...
using Our.Umbraco.Vorto.Extensions
You should always aim for using strongly typed content if you can :)
...and just in case you were doing this; don't ever use the ContentService.GetByXxxx for fetching content to use in rendering - that one works directly with the database and not the cached content and should only be used when you need to actually update things!
Regarding the using statement, Visual Studio should help you adding the right using statements needed as long as you have the Vorto DLLs referenced in the project where you are trying to use it. I think it might just need a using statement for Our.Umbraco.Vorto ... I'm not completely sure as I don't have a project right here using Vorto so these things are a bit from memory.
Yes - those assumptions are correct. CultureName is optional in case you didn't notice ... I think it will use the current culture if nothing is specified but you can play around with that until it does what you want.
On how to pass data from your controller to your view, this is really just basic MVC stuff. I would recommend that you take a look at some of the many MVC tutorials out there as they do a very good job at describing how to construct your model in your controller and then pass this to a View and have it rendered. This is not as such very Umbraco-related so any tutorial should give you an idea of how this works.
Take a look at the Using a Model to pass information to our View part of this article, which is showing how to deal with models and views:
Just for your information, I am trying to explain this issue in more brief.
This is the property name Page Title whose alias "pageTitle" I am trying to access in a controller via page(node) whose node_id is 1050, due to which the command becomes as follows..
var value = Umbraco.TypedContent(1050).GetVortoValue("pageTitle", "cultureName");
after this I entered (as per Trial and Error)
TempData["Message"] = View(value);
which returns
System.Web.Mvc.ViewResult
in the view output.
If I am closer to the solution here, please suggest how to get onto the conclusion so that the Japanese text corresponding to Page Title is displayed in view.
Regarding the links, I am going through it to get to the solution.
TempData is not really the way you are supposed to pass around data to your views. Also - I'm not really sure what you are trying to do by assigning View(value) to TempData... that would not really do you any good.
Make sure to go through the tutorials and documentation I've linked - you really need the basic knowledge of how to work with MVC, create a model class that corresponds to your view, populate it with the data you need and then pass it on to the view.
You should get the hang of all this before you start trying to implement it in your Umbraco solution.
You should also make sure to take note of the parts about route hijacking with controllers when you read the Umbraco documentation, since I think that will be what you need.
Calling Vorto Property Values inside Model and Controller in Umbraco
Hello,
Till Now, I have implemented Vorto property values inside a View file (.cshtml) for a multilingual project by using...
@using Our.Umbraco.Vorto.Extensions
and then...
@Model.Content.GetVortoValue("propertyAlias");
Just wanted to know to implement or call Vorto Property Values inside a Model or Controller.
Regards,
Mangirish
Hi Mangirish,
You can access Vorto values the same way as you would do in your view. IPublishedContent (which is what you're using in your views) is also what you should be using in your controllers:
Hello Claus.
Thanks very much! So you mean that we have to use strongly typed content to get the values. but, is it necessary to add... using Our.Umbraco.Vorto.Extensions
before using this?
Please guide further.
Regards,
You should always aim for using strongly typed content if you can :)
...and just in case you were doing this; don't ever use the ContentService.GetByXxxx for fetching content to use in rendering - that one works directly with the database and not the cached content and should only be used when you need to actually update things!
Regarding the using statement, Visual Studio should help you adding the right using statements needed as long as you have the Vorto DLLs referenced in the project where you are trying to use it. I think it might just need a using statement for Our.Umbraco.Vorto ... I'm not completely sure as I don't have a project right here using Vorto so these things are a bit from memory.
Hello Claus,
Some developments from my side. Added reference for dll and used it inside my controller by using this directive....
Secondly, used this according to my understandings that (1) stands for (node_id) and "alias" stands for "propertyAlias"
Just some more suggestions needed from your side please, as I am novice in MVC....
Previously just a string was printed in this manner...
How to print the value of variable instead of "Sample Text"
Please help me further.
Regards,
Mangirish
Yes - those assumptions are correct. CultureName is optional in case you didn't notice ... I think it will use the current culture if nothing is specified but you can play around with that until it does what you want.
On how to pass data from your controller to your view, this is really just basic MVC stuff. I would recommend that you take a look at some of the many MVC tutorials out there as they do a very good job at describing how to construct your model in your controller and then pass this to a View and have it rendered. This is not as such very Umbraco-related so any tutorial should give you an idea of how this works.
Take a look at the Using a Model to pass information to our View part of this article, which is showing how to deal with models and views:
https://www.asp.net/mvc/overview/older-versions/mvc-music-store/mvc-music-store-part-3
When you got your head around that, I suggest you read through:
https://our.umbraco.org/documentation/reference/templating/mvc/
and the Controllers and Custom Routing parts here:
https://our.umbraco.org/documentation/Implementation/
Hello Claus,
Just for your information, I am trying to explain this issue in more brief.
This is the property name Page Title whose alias "pageTitle" I am trying to access in a controller via page(node) whose node_id is 1050, due to which the command becomes as follows..
after this I entered (as per Trial and Error)
which returns
System.Web.Mvc.ViewResult
in the view output.
If I am closer to the solution here, please suggest how to get onto the conclusion so that the Japanese text corresponding to Page Title is displayed in view.
Regarding the links, I am going through it to get to the solution.
Cheers,
Mangirish
TempData is not really the way you are supposed to pass around data to your views. Also - I'm not really sure what you are trying to do by assigning
View(value)
to TempData... that would not really do you any good.Make sure to go through the tutorials and documentation I've linked - you really need the basic knowledge of how to work with MVC, create a model class that corresponds to your view, populate it with the data you need and then pass it on to the view. You should get the hang of all this before you start trying to implement it in your Umbraco solution.
You should also make sure to take note of the parts about route hijacking with controllers when you read the Umbraco documentation, since I think that will be what you need.
is working on a reply...