In the front page , we are displaying 6 persons id randomly . The code is given below.
var lecturers = Umbraco.Content(1186);
foreach (var item in lecturers.Children.Where("Visible").Random(6))
now i want to have 6 persons id statically . How can i do that. Can you please help me.
I am using Multinode Treepicker now . After I followed the whole procedure as suggested, I wrote @CurrentPage.fsMNTP which displays only ids. When i finish writing the code, it is not displaying anything.
It is displying error now. Can you please help me.
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 1: @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
Line 2:
Line 3: @foreach (var lecturer in Model.Content.GetPropertyValue<>
I am disturbing a lot . I am really sorry about that . Again it is displaying error .
umbraco version : 7.1.4 , I am using MultiNodeTreePicker.
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 10: if (lecturer.HasValue("profilePicture"))
Line 11: {
Line 12: var lecturerProfilePicture = lecturer.GetPropertyValue
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'Umrbaco' does not exist in the current context
Source Error:
Line 10: if (lecturer.HasValue("profilePicture"))
Line 11: {
Line 12: var lecturerProfilePicture = Umrbaco.TypedMedia(lecturer.GetPropertyValue
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 10: if (lecturer.HasValue("profilePicture"))
Line 11: {
Line 12: var lecturerProfilePicture = Umbraco.TypedMedia(lecturer.GetPropertyValue
I've recreated this locally and it works. If the below still doesn't work can you please check the aliases in the code against what you have in the document type - also provide a screenshot of these fields (in the settings -> document types).
@if (Model.Content.HasValue("fsMNTP"))
{
var lecturerListValue = Model.Content.GetPropertyValue<string>("fsMNTP");
var lecturerList = lecturerListValue.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
var lecturerCollection = Umbraco.TypedContent(lecturerList).Where(x => x != null);
foreach (var lecturer in lecturerCollection)
{
if (lecturer.HasValue("profilePicture"))
{
var lecturerProfilePicture = Umbraco.TypedMedia(lecturer.GetPropertyValue<int>("profilePicture"));
<a href="@lecturer.Url">
<div class="frontpage lecturer box">
<div class="left">
<img src="@lecturerProfilePicture.Url" />
</div>
<div class="right">
<strong>@lecturer.Name</strong>
<p>
@{
var lecturerIntro = lecturer.GetPropertyValue<HtmlString>("introToLecturer");
if (lecturerIntro.ToString().Length > 130)
{
@Umbraco.Truncate(lecturerIntro, 130) <text>...</text>
}
else
{
@lecturerIntro
}
}
</p>
</div>
<div class="clear"></div>
</div>
</a>
}
}
}
Because I need to show the pictures and descriptions also . I am sure that there is a problem in picture and description coding part. Now i do not know how to make picture and display code. Can you please help me.
If the below still doesn't work can you please check the aliases in the code against what you have in the document type - also provide a screenshot of these fields (in the settings -> document types).
Sorry I'm not sure I understand what you're asking:
"Can we connect main folder ids and children ids."
These IDs can be viewed on the properties tab of each node. I think your issue with the profile picture is that you've used a type "Upload" - this should be a media picker. If you're hacking this stuff on live you might just want to create a new profile picture media field and set these all again.
Yes , you are right. I changed media picker. now it works profile picture.
But description is displaying error.
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 22: @{
Line 23: var lecturerIntro = lecturer.GetPropertyValue
I'm assuming you've changed the profile intro text to be a RTE type.
The Umbraco.Truncate adds a ... so you don't need the one in which will also be outside of the
from the Rich Text editor.
I suggest that if you have these issues in the future try little snippets and view the source of the page. It will help you understand what's happening.
Thank you very much for the all feed back. I take note of your comments and appreciate your help.
I started to work in umbraco for three months back. I want to learn more about umbraco and become good at it . How can i do that. Can you give me suggestion.
Statically
Hello Team,
I need a small favour.
This is my website http://euforedrag.dk/
In the front page , we are displaying 6 persons id randomly . The code is given below.
var lecturers = Umbraco.Content(1186);
foreach (var item in lecturers.Children.Where("Visible").Random(6)) now i want to have 6 persons id statically . How can i do that. Can you please help me.
Hi there
You can probably just remove the
from your example?
Jules
Add a multi node content picker, set the min and max to 6, to your homepage called "lecturers" - then loop through that.
See here for an example
https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/Multinode-Treepicker2
Hi ,
I have 48 (employees ids ) in the front page . The ids keep rotating when i refresh. Now i want to change it.
I want to have only 6 ids out of 48 ids to be permanent always. How can i stop the automatic rotation.
If i remove automatic rotation, all the 48ids are displaying in the front page.
var lecturers = Umbraco.Content(1186); foreach (var item in lecturers.Children.Where("Visible").Random(6))
Can you please help me.
Use .Take(6) instead, maybe?
Then you can sort the child nodes, as the top six will then be shown in the list.
Hi ,
Thanks for your replay. If i use Take , it is displaying the first 6 list. I don't want like that. I need to chose particular 6 ids out of 48 ids.
As Steve mentioned, use the Multinode Treepicker to choose the particular 6 lecturers you want to be shown on the homepage. There are a ton of examples of how to use the Multinode Treepicker, including at the example on the page Steve sent you to: https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/Multinode-Treepicker2
After you have given a solid attempt at using the MNTP, feel free to ask specific questions if you run into issues.
Hi All,
I am using Multinode Treepicker now . After I followed the whole procedure as suggested, I wrote @CurrentPage.fsMNTP which displays only ids. When i finish writing the code, it is not displaying anything.
This is my code:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
}
I think you need to leave behind dynamic objects- they tend to just cause issues later!
Try this
I've also simplified your truncate of the long intros.. I'm guessing your text is rich text - if it's not then this will probably error.
HTH
Steve
Hi Steve,
It is displying error now. Can you please help me.
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 1: @inherits Umbraco.Web.Mvc.UmbracoTemplatePage Line 2:
Line 3: @foreach (var lecturer in Model.Content.GetPropertyValue<>
Source File: e:\wwwroot\deo\euforedrag.dk\Views\Partials\LecturerListFrontpage.cshtml Line: 3
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] ASP.PageViewsPartialsLecturerListFrontpagecshtml.Execute() in e:\wwwroot\deo\euforedrag.dk\Views\Partials\LecturerListFrontpage.cshtml:3 System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +251 System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +151 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +118 Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +230 System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper htmlHelper, String partialViewName) +107 ASP.PageViewsHomePage_cshtml.Execute() in e:\wwwroot\deo\euforedrag.dk\Views\HomePage.cshtml:12 System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +251 System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +151 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +103 Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +230 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +356 System.Web.Mvc.<>cDisplayClass1a.17() +30 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func
1 continuation) +415 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func
1 continuation) +415 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +627 System.Web.Mvc.<>cDisplayClass1d.19() +36 System.Web.Mvc.Async.<>cDisplayClass1.0() +22 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +64 System.Web.Mvc.Async.<>cDisplayClass4.3(IAsyncResult ar) +22 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +50 System.Web.Mvc.<>cDisplayClass8.3(IAsyncResult asyncResult) +38 System.Web.Mvc.Async.<>cDisplayClass4.3(IAsyncResult ar) +22 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +50 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +607 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +134Hi,
What version of Umbraco are you using - and did you use the obsolete Multi node tree picker?
Try this;
UPDATED: fixed a code error
Hi Steve,
I am disturbing a lot . I am really sorry about that . Again it is displaying error . umbraco version : 7.1.4 , I am using MultiNodeTreePicker.
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 10: if (lecturer.HasValue("profilePicture")) Line 11: { Line 12: var lecturerProfilePicture = lecturer.GetPropertyValue
Source File: e:\wwwroot\deo\euforedrag.dk\Views\Partials\LecturerListFrontpage.cshtml Line: 12
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] ASP.PageViewsPartialsLecturerListFrontpagecshtml.Execute() in e:\wwwroot\deo\euforedrag.dk\Views\Partials\LecturerListFrontpage.cshtml:12 System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +251 System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +146 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +118 Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +230 System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper htmlHelper, String partialViewName) +95 ASP.PageViewsHomePage_cshtml.Execute() in e:\wwwroot\deo\euforedrag.dk\Views\HomePage.cshtml:12 System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +251 System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +146 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +103 Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +230 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +374 System.Web.Mvc.<>cDisplayClass1a.17() +30 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func
1 continuation) +436 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func
1 continuation) +436 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +662 System.Web.Mvc.<>cDisplayClass1d.19() +39 System.Web.Mvc.Async.<>cDisplayClass1.0() +22 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52 System.Web.Mvc.Async.<>cDisplayClass4.3(IAsyncResult ar) +22 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38 System.Web.Mvc.<>cDisplayClass8.3(IAsyncResult asyncResult) +41 System.Web.Mvc.Async.<>cDisplayClass4.3(IAsyncResult ar) +22 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +607 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +134Oopps =- missed something, try the code again (I just updated it).
You did not attach the code.
No - I updated the previous post.
Again it is displaying error,
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'Umrbaco' does not exist in the current context
Source Error:
Line 10: if (lecturer.HasValue("profilePicture")) Line 11: { Line 12: var lecturerProfilePicture = Umrbaco.TypedMedia(lecturer.GetPropertyValue
Source File: e:\wwwroot\deo\euforedrag.dk\Views\Partials\LecturerListFrontpage.cshtml Line: 12
I have changed Umrbaco spelling .
again it is displaying error
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 10: if (lecturer.HasValue("profilePicture")) Line 11: { Line 12: var lecturerProfilePicture = Umbraco.TypedMedia(lecturer.GetPropertyValue
Source File: e:\wwwroot\deo\euforedrag.dk\Views\Partials\LecturerListFrontpage.cshtml Line: 12
Hi,
I've recreated this locally and it works. If the below still doesn't work can you please check the aliases in the code against what you have in the document type - also provide a screenshot of these fields (in the settings -> document types).
As you suggested, i pasted your code . The name and URL is working . The name and URL work only when the description and picture code is deleted.
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@if (Model.Content.HasValue("fsMNTP")) { var lecturerListValue = Model.Content.GetPropertyValue
Because I need to show the pictures and descriptions also . I am sure that there is a problem in picture and description coding part. Now i do not know how to make picture and display code. Can you please help me.
Please see my note above:
If the below still doesn't work can you please check the aliases in the code against what you have in the document type - also provide a screenshot of these fields (in the settings -> document types).
Hi Steve,
I provided a screenshot of these fields.
hi,
I think you need to change the upload to a media picker.
Steve
Hi ,
Fine. I have a little bit doubt ,
I have a main folder id (1186) , in the children ids (1101,1102,1103,1104,1105,1106). Can we connect main folder ids and children ids.
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{ var lecturers = Umbraco.Content(1186);
}
Sorry I'm not sure I understand what you're asking:
"Can we connect main folder ids and children ids."
These IDs can be viewed on the properties tab of each node. I think your issue with the profile picture is that you've used a type "Upload" - this should be a media picker. If you're hacking this stuff on live you might just want to create a new profile picture media field and set these all again.
HTH
Steve
Hi,
Yes , you are right. I changed media picker. now it works profile picture.
But description is displaying error.
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 22: @{ Line 23: var lecturerIntro = lecturer.GetPropertyValue
Source File: e:\wwwroot\deo\euforedrag.dk\Views\Partials\LecturerListFrontpage.cshtml Line: 24
hi,
This issue is that you're using Umbraco.Truncate - I thought you had a rich text editor - you don't.
Either swap the profile intro to use the rich text editor if you want editors to be able to enter rich text or change it back to how you had it.
The fact you're using Html.Raw makes me think you're putting html in there though!
Hello Steve,
I have a little problem with profile intro. Why is dot coming in the down, its repeating two times.
see my sample picture
var lecturerIntro = lecturer.GetPropertyValue
I'm assuming you've changed the profile intro text to be a RTE type.
The Umbraco.Truncate adds a ... so you don't need the one in which will also be outside of the
from the Rich Text editor.
I suggest that if you have these issues in the future try little snippets and view the source of the page. It will help you understand what's happening.
Hi Steve,
Thank you very much for the all feed back. I take note of your comments and appreciate your help. I started to work in umbraco for three months back. I want to learn more about umbraco and become good at it . How can i do that. Can you give me suggestion.
Hi,
I think you should look to take the training courses - they are excellent!
https://umbraco.com/training/book-courses/ look for the Umbraco Fundamentals course
If you could mark this thread as solved that would be great
Steve
is working on a reply...