Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ruban 18 posts 88 karma points
    Dec 03, 2017 @ 21:05
    Ruban
    0

    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)) enter image description here now i want to have 6 persons id statically . How can i do that. Can you please help me.

  • Jules 276 posts 587 karma points
    Dec 04, 2017 @ 09:26
    Jules
    0

    Hi there

    You can probably just remove the

    .Random(6)
    

    from your example?

    Jules

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Dec 04, 2017 @ 10:29
    Steve Morgan
    0

    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

  • Ruban 18 posts 88 karma points
    Dec 04, 2017 @ 18:59
    Ruban
    0

    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.

  • Jannik Anker 48 posts 258 karma points c-trib
    Dec 04, 2017 @ 19:02
    Jannik Anker
    0

    Use .Take(6) instead, maybe?

    Then you can sort the child nodes, as the top six will then be shown in the list.

  • Ruban 18 posts 88 karma points
    Dec 04, 2017 @ 21:04
    Ruban
    0

    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.

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Dec 04, 2017 @ 21:39
    Nicholas Westby
    0

    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.

  • Ruban 18 posts 88 karma points
    Dec 05, 2017 @ 11:35
    Ruban
    0

    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

    @{

    foreach (var lecturers in CurrentPage.fsMNTP)
    {
        var item = Umbraco.Content(lecturers);
    
        <a href="@item.Url">
        <div class="frontpage lecturer box">
            <div class="left">
            <img src="@item.profilePicture" />
            </div>
            <div class="right">
                <strong>@item.Name</strong>
                <p>
                @if (@item.introToLecturer.ToString().Length > 130) {
                    @Html.Raw(@item.introToLecturer.ToString().Substring(0, 130))<text>...</text>
                }else{
                    @Html.Raw(@item.introToLecturer.ToString())
                }
                </p>
            </div>
    
                <div class="clear"></div>
        </div>
                    </a>
    }
    <div style="text-align: center">
    <a style="color: #FFF!important; margin-top: 20px;" class="button small white" href="/foredragsholdere">Alle foredragsholdere</a>
    </div>
    

    } enter image description here

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Dec 05, 2017 @ 12:40
    Steve Morgan
    0

    I think you need to leave behind dynamic objects- they tend to just cause issues later!

    Try this

        @foreach (var lecturer in Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("fsMNTP"))
    {
        if (lecturer.HasValue("profilePicture"))
        {
            var lecturerProfilePicture = lecturer.GetPropertyValue<IPublishedContent>("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>
        }
    }
    

    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

  • Ruban 18 posts 88 karma points
    Dec 05, 2017 @ 12:51
    Ruban
    0

    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, Func1 continuation) +415 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 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) +134

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Dec 05, 2017 @ 13:17
    Steve Morgan
    0

    Hi,

    What version of Umbraco are you using - and did you use the obsolete Multi node tree picker?

    Try this;

    @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 = Umrbaco.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>
            }
        }
    }
    

    UPDATED: fixed a code error

  • Ruban 18 posts 88 karma points
    Dec 05, 2017 @ 13:50
    Ruban
    0

    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, Func1 continuation) +436 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 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) +134

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Dec 05, 2017 @ 13:59
    Steve Morgan
    0

    Oopps =- missed something, try the code again (I just updated it).

  • Ruban 18 posts 88 karma points
    Dec 05, 2017 @ 14:13
    Ruban
    0

    You did not attach the code.

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Dec 05, 2017 @ 14:23
    Steve Morgan
    0

    No - I updated the previous post.

  • Ruban 18 posts 88 karma points
    Dec 05, 2017 @ 14:27
    Ruban
    0

    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

  • Ruban 18 posts 88 karma points
    Dec 05, 2017 @ 14:32
    Ruban
    0

    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

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Dec 05, 2017 @ 15:13
    Steve Morgan
    0

    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).

    @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>
                }
            }
        }
    
  • Ruban 18 posts 88 karma points
    Dec 06, 2017 @ 08:41
    Ruban
    0

    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

        foreach (var lecturer in lecturerCollection)
        {
            if (lecturer.HasValue("profilePicture"))
            {
    
                <a href="@lecturer.Url">
                    <div class="frontpage lecturer box">
                        <div class="left">
    
                        </div>
                        <div class="right">
                            <strong>@lecturer.Name</strong>
    
                        </div>
    
                        <div class="clear"></div>
                    </div>
                </a>
            }
        }
    }
    

    enter image description here

    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.

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Dec 06, 2017 @ 08:59
    Steve Morgan
    0

    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).

  • Ruban 18 posts 88 karma points
    Dec 06, 2017 @ 09:14
    Ruban
    0

    enter image description here

  • Ruban 18 posts 88 karma points
    Dec 06, 2017 @ 09:17
    Ruban
    0

    enter image description here

    enter image description here

  • Ruban 18 posts 88 karma points
    Dec 06, 2017 @ 11:06
    Ruban
    0

    Hi Steve,

    I provided a screenshot of these fields.

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Dec 06, 2017 @ 12:29
    Steve Morgan
    0

    hi,

    I think you need to change the upload to a media picker.

    Steve

  • Ruban 18 posts 88 karma points
    Dec 06, 2017 @ 12:53
    Ruban
    0

    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);

    foreach (var item in lecturers.Children.Where("Visible").Random(6))
    {
        <a href="@item.Url">
        <div class="frontpage lecturer box">
            <div class="left">
            <img src="@item.profilePicture" />
            </div>
            <div class="right">
                <strong>@item.Name</strong>
                <p>
                @if (@item.introToLecturer.ToString().Length > 130) {
                    @Html.Raw(@item.introToLecturer.ToString().Substring(0, 130))<text>...</text>
                }else{
                    @Html.Raw(@item.introToLecturer.ToString())
                }
                </p>
            </div>
    
                <div class="clear"></div>
        </div>
                    </a>
    }
    <div style="text-align: center">
    <a style="color: #FFF!important; margin-top: 20px;" class="button small white" href="/foredragsholdere">Alle foredragsholdere</a>
    </div>
    

    }

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Dec 06, 2017 @ 13:27
    Steve Morgan
    0

    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

  • Ruban 18 posts 88 karma points
    Dec 06, 2017 @ 14:20
    Ruban
    0

    Hi,

    Yes , you are right. I changed media picker. now it works profile picture.

    enter image description here

    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

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Dec 06, 2017 @ 14:34
    Steve Morgan
    0

    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!

    @if (@item.introToLecturer.ToString().Length > 130) {
                @Html.Raw(@item.introToLecturer.ToString().Substring(0, 130))<text>...</text>
            }else{
                @Html.Raw(@item.introToLecturer.ToString())
            }
    
  • Ruban 18 posts 88 karma points
    Dec 07, 2017 @ 09:40
    Ruban
    0

    Hello Steve,

    I have a little problem with profile intro. Why is dot coming in the down, its repeating two times.

    see my sample pictureenter image description here

    var lecturerIntro = lecturer.GetPropertyValue

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Dec 07, 2017 @ 09:54
    Steve Morgan
    0

    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.

  • Ruban 18 posts 88 karma points
    Dec 07, 2017 @ 12:28
    Ruban
    0

    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.

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Dec 07, 2017 @ 13:34
    Steve Morgan
    1

    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

Please Sign in or register to post replies

Write your reply to:

Draft