Last chance to get discounted tickets to Codegarden... Price goes up on Tuesday at 20:00 CEST!

Copied to clipboard

Flag this post as spam?

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


  • Jhon 65 posts 138 karma points
    1 week ago
    Jhon
    0

    I can not see anything in my output

    Hi ,

    I have written this code but is not showing any error and i can not see out put.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
    var node = Model.Content;
    
    
    }
    
    @foreach (var rejse in node.Children) {
    
    
                <div class="rejseContainer row">
    
    
                        <div id="toClear"></div>                        
                        <div class="rejseText col-md-7 col-lg-8">
                            <h1>@rejse.GetPropertyValue("titel")</h1>
    
                            <h2>@rejse.GetPropertyValue("subtitle")</h2>
                            <p style="max-width: 600px;">@rejse.GetPropertyValue("teaser")</p>
                        </div>
    
            </div>
    
    }
    

    see my document type.

    enter image description here

    output: enter image description here

    Content :

    enter image description here

  • Jhon 65 posts 138 karma points
    1 week ago
    Jhon
    0

    Can anyone help me?

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    1 week ago
    Michaël Vanbrabandt
    0

    Hi Jhon,

    where and how do you call this partial view? Can you it to us?

    Thanks!

    /Michaël

  • Jhon 65 posts 138 karma points
    1 week ago
    Jhon
    0

    I attached template and partial view files.

    enter image description here

    enter image description here

  • Jhon 65 posts 138 karma points
    1 week ago
    Jhon
    0

    Hi Michael,

    What is the mistake? Can you please share.

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    1 week ago
    Michaël Vanbrabandt
    0

    Hi Jhon,

    the template Rejser Liste by which content nodes are these used? In your structure I see first Rejser and as a child 2018 and then the other childs which you want to display in the view.

    If you call this partial view from the page Rejser it won't work because you access the direct children which in your case is the node 2018.

    To display the other nodes you can use Descendants() where you filter on the Document Type alias of the nodes you want to view.

    https://our.umbraco.org/documentation/reference/querying/ipublishedcontent/Collections#descendants

    So on your Rejser page you can get the nodes by using:

    var nodes = Model.Content.Descendants().Where(x => x.DocumentTypeAlias == "theAliasOfYourNodes");
    

    Then using the foreach you can loop over these nodes and display the html into the frontend.

    Hope this helps!

    /Michaël

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    1 week ago
    Michaël Vanbrabandt
    0

    Hi Jhon,

    any news on this, did you solved the issue?

    Thanks!

    /Michaël

  • Jhon 65 posts 138 karma points
    1 week ago
    Jhon
    0

    Hi Michael,

    Thank you so much for your help i really appreciate it. It works fine. I am little busy with my exam . Therefore i can not chat with you. Sorry for the late reply.

    Now i have a problem Media picker. I want to display one image from media picker not multiple image.

    See my coding

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ var node = Model.Content.Descendants().Where(x => x.DocumentTypeAlias == "Arrangement");

    }

    @foreach (var rejse in node) {

        <div class="rejseContainer row">
            <div class="top col-md-5 col-lg-4">        
        @{
            var typedMediaPickerSingle = Model.Content.GetPropertyValue<IPublishedContent>("image");
            if (typedMediaPickerSingle != null)
            {
                <p>@typedMediaPickerSingle.Url</p>
                <img src="@typedMediaPickerSingle.Url" style="width:200px" alt="@typedMediaPickerSingle.GetPropertyValue("alt")" />
            }
        } 
            </div>  
                <div id="toClear"></div>                        
                <div class="rejseText col-md-7 col-lg-8">
                    <h1>@rejse.GetPropertyValue("titel")</h1>
    
                    <h2>@rejse.GetPropertyValue("subtitle")</h2>
                    <p style="max-width: 600px;">@rejse.GetPropertyValue("teaser")</p>
                </div>
    
    </div>
    

    }

    Image is not displying , See my output:

    enter image description here

  • Jhon 65 posts 138 karma points
    1 week ago
    Jhon
    0

    Can anyone please help me?

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    1 week ago
    Michaël Vanbrabandt
    0

    Hi Jhon,

    did you set the option to disable multi select on the media picker datatype?

    https://our.umbraco.org/documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Media-Picker2#data-type-definition-example

    Hope this helps!

    /Michaël

  • Jhon 65 posts 138 karma points
    1 week ago
    Jhon
    0

    Yes , I saw. see my datatype.

    enter image description here

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    1 week ago
    Michaël Vanbrabandt
    0

    Jhon,

    And you have selected an image in the content node?

    /Michaël

  • Jhon 65 posts 138 karma points
    1 week ago
    Jhon
    0

    yes, see belowenter image description here

    I can not understand , why is not displaying.

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    1 week ago
    Michaël Vanbrabandt
    0

    Ok think I found it:

    change:

    var typedMediaPickerSingle = Model.Content.GetPropertyValue<IPublishedContent>("image");
    

    to:

    var typedMediaPickerSingle = rejse.GetPropertyValue<IPublishedContent>("image");
    

    Because you are accessing the wrong object, you need to access the one from your foreach like the other properties.

    Hope this helps!

    /Michaël

  • Jhon 65 posts 138 karma points
    1 week ago
    Jhon
    1

    Michael ,

    Thank you very much for your kind guidance. It works fine.

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    1 week ago
    Michaël Vanbrabandt
    0

    Hi Jhon,

    no problem! Glad I could help you out.

    Have a nice day!

    /Michaël

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    1 week ago
    Michaël Vanbrabandt
    0

    Jhon,

    don't forget to mark the answer so that others with the same issue can find the solution.

    Enjoy Umbraco!

    /Michaël

  • Jhon 65 posts 138 karma points
    1 week ago
    Jhon
    0

    I want to display Start date and end date in order by (startdate). How can i do thaat. Can you please provide any example in the doc.

    Like that :

    enter image description here

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    1 week ago
    Michaël Vanbrabandt
    0

    HI Jhon,

    you mean the builtin published at and unpublished at dates or are you using custom date properties?

    https://our.umbraco.org/Documentation/Reference/Querying/IPublishedContent/Collections#orderby

    /Michaël

  • Jhon 65 posts 138 karma points
    1 week ago
    Jhon
    0

    Hi ,

    I wrote date function. What is the mistake here?

    see my code:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @{

    var rejse = Model.Content;

    }

    string dateCaption1 = "Startdate: " + @rejse.GetPropertyValue("startTime").ToString("d. MMMM yyyy", CultureInfo.CreateSpecificCulture("da-DK"));
    string dateCaption2 = "Enddate: " + @rejse.("endTime").ToString("d. MMMM yyyy", CultureInfo.CreateSpecificCulture("da-DK"));
    
                <div class="rejseInfo">
                <div class="rejseDate">
                <p style="padding-top: 4px; margin-bottom: 5px;">@dateCaption1</p>
                    <p>@dateCaption2</p>
                </div>
    
    
        <div class="bot">
            <h2>@rejse.GetPropertyValue("subtitle")</h2>
            <h1>@rejse.GetPropertyValue("title")</h1>
            <p style="font-weight: bold;">@rejse.GetPropertyValue("teaser")</p>
            <p>@rejse.GetPropertyValue("bodyText")</p>
        </div>
    </div>
    

    It is displying error.

    enter image description here

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    1 week ago
    Michaël Vanbrabandt
    0

    Hi Jhon,

    you need to place these 2 lines inside braces like:

    @{
    
    var rejse = Model.Content;
    string dateCaption1 = "Startdate: " + @rejse.GetPropertyValue("startTime").ToString("d. MMMM yyyy", CultureInfo.CreateSpecificCulture("da-DK"));
    string dateCaption2 = "Enddate: " + @rejse.("endTime").ToString("d. MMMM yyyy", CultureInfo.CreateSpecificCulture("da-DK"));
    
    }
    

    Hope this helps.

    /Michaël

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    1 week ago
    Michaël Vanbrabandt
    0

    Hi Jhon,

    did you solved your issue? Can you report back to the community? Thanks!

    /Michaël

  • Jhon 65 posts 138 karma points
    7 days ago
    Jhon
    0

    Hi, Yes , i Placed it. It is displaying error. See my coding

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @{

     var rejse = Model.Content;
     string dateCaption1 = "Startdate: " + @rejse.GetPropertyValue("startTime").ToString("d. MMMM yyyy", CultureInfo.CreateSpecificCulture("da-DK"));
    string dateCaption2 = "Enddate: " + @rejse.GetPropertyValue("endTime").ToString("d. MMMM yyyy", CultureInfo.CreateSpecificCulture("da-DK"));
    

    }

                <div class="rejseInfo">
                <div class="rejseDate">
                <p style="padding-top: 4px; margin-bottom: 5px;">@dateCaption1</p>
                    <p>@dateCaption2</p>
                </div>
    
    
        <div class="bot">
            <h2>@rejse.GetPropertyValue("subtitle")</h2>
            <h1>@rejse.GetPropertyValue("title")</h1>
            <p style="font-weight: bold;">@rejse.GetPropertyValue("teaser")</p>
            <p>@rejse.GetPropertyValue("bodyText")</p>
        </div>
    </div>
    

    See error:

    enter image description here

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    7 days ago
    Michaël Vanbrabandt
    0

    Hi Jhon,

    could you translate the exception to english?

    The part from

    CS0103: .... 'CultureInfo'...

    Thanks!

    /Michaël

  • Jhon 65 posts 138 karma points
    7 days ago
    Jhon
    0

    CS0103: The name 'CultureInfo' does not exist in the current context

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    7 days ago
    Michaël Vanbrabandt
    0

    Jhon,

    You're probably missing a "using namespace System.Globalization;" to include the lirbary for the CultureInfo.

    Have a nice day!

    /Michaël

  • Jhon 65 posts 138 karma points
    7 days ago
    Jhon
    0

    yes i added like that ,

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @using System.Globalization;

    again it is displying error.

    Compiler Error Message: CS1501: No overload for the 'ToString' method uses 2 arguments

    enter image description here

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    7 days ago
    Michaël Vanbrabandt
    0

    Jhon,

    try to specify the returning type of your GetpropertyValue for both, eg:

     @rejse.GetPropertyValue<DateTime>("startTime")
    

    and

     @rejse.GetPropertyValue<DateTime>("endTime")
    

    Hope this helps!

    /Michaël

  • Jhon 65 posts 138 karma points
    7 days ago
    Jhon
    0

    Hi Michael,

    It is displying error .

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @using System.Globalization;

    @{

     var rejse = Model.Content;
        string dateCaption1 = "Startdate: " +  @rejse.GetPropertyValue<DateTime>("startTime");
        string dateCaption2 = "Enddate: " +  @rejse.GetPropertyValue<DateTime>("endTime");
    

    }

                <div class="rejseInfo">
                <div class="rejseDate">
                <p style="padding-top: 4px; margin-bottom: 5px;">@dateCaption1</p>
                    <p>@dateCaption2</p>
                </div>
    
    
        <div class="bot">
            <h2>@rejse.GetPropertyValue("subtitle")</h2>
            <h1>@rejse.GetPropertyValue("title")</h1>
            <p style="font-weight: bold;">@rejse.GetPropertyValue("teaser")</p>
            <p>@rejse.GetPropertyValue("bodyText")</p>
        </div>
    </div>
    

    See error: I closed properly , why is it displying error.

    enter image description here

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    7 days ago
    Michaël Vanbrabandt
    0

    Hi John,

    you removed the ToString part from your dates.

    string dateCaption1 = "Startdate: " + @rejse.GetPropertyValue<DateTime>("startTime").ToString("d. MMMM yyyy", CultureInfo.CreateSpecificCulture("da-DK"));
    string dateCaption2 = "Enddate: " + @rejse.GetPropertyValue<DateTime>("endTime").ToString("d. MMMM yyyy", CultureInfo.CreateSpecificCulture("da-DK"));
    

    /Michaël

  • Jhon 65 posts 138 karma points
    6 days ago
    Jhon
    0

    Sorry , i added .

    again it is displying same error

    enter image description here

    See coding

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @using System.Globalization;

    @{

    var rejse = Model.Content; string dateCaption1 = "Startdate: " + @rejse.GetPropertyValue< DateTime>("startTime").ToString("d. MMMM yyyy", CultureInfo.CreateSpecificCulture("da-DK")); string dateCaption2 = "Enddate: " + @rejse.GetPropertyValue< DateTime>("endTime").ToString("d. MMMM yyyy", CultureInfo.CreateSpecificCulture("da-DK"));

    }

                <div class="rejseInfo">
                <div class="rejseDate">
                <p style="padding-top: 4px; margin-bottom: 5px;">@dateCaption1</p>
                    <p>@dateCaption2</p>
                </div>
    
    
        <div class="bot">
            <h2>@rejse.GetPropertyValue("subtitle")</h2>
            <h1>@rejse.GetPropertyValue("title")</h1>
            <p style="font-weight: bold;">@rejse.GetPropertyValue("teaser")</p>
            <p>@rejse.GetPropertyValue("bodyText")</p>
        </div>
    </div>
    
  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    6 days ago
    Michaël Vanbrabandt
    0

    Hi Jhon,

    is there a space in front of the datetime in .GetProperty< DateTime>(... ?

    /Michaël

  • Jhon 65 posts 138 karma points
    6 days ago
    Jhon
    0

    No space

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    6 days ago
    Michaël Vanbrabandt
    0

    Its really hard to see the mistake, could you add the complete content of your partial view and format it nicely in this post?

    /Michaël

  • Jhon 65 posts 138 karma points
    6 days ago
    Jhon
    0

    See below my code

    enter image description here

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    6 days ago
    Michaël Vanbrabandt
    0

    Jhon,

    remove the @ in front of both @rejse because you are in a razor block by using @{ ..... }

    Hope this helps.

    /Michaël

  • Jhon 65 posts 138 karma points
    6 days ago
    Jhon
    0

    what happened Michael?

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    6 days ago
    Michaël Vanbrabandt
    0

    What do you mean?

    /Michaël

  • Jhon 65 posts 138 karma points
    6 days ago
    Jhon
    1

    Thank you so much , It works fine. When i am learning Umbraco , I feel little bit hard but I am interesting to learn Umbraco .Thank you very much for your kind support.

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    6 days ago
    Michaël Vanbrabandt
    0

    Jhon,

    no problem that's why we are the most friendliest community!

    Also look at umbraco.tv where you find many videos for learning Umbaco!

    Have a nice day!

    /Michaël

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    6 days ago
    Michaël Vanbrabandt
    0

    Hi Jhon,

    don't forget to mark the answer for this thread.

    Have a nice day and keep on enjoying the Umbraco CMS!

    /Michaël

  • Jhon 65 posts 138 karma points
    6 days ago
    Jhon
    0

    Hi Michael,

    The same code i have written another format, it is displaying error. What is the mistake here.

    enter image description here

    See output:

    Compiler Error Message: CS1928: 'System.Collections.Generic.IEnumerable

    enter image description here

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    6 days ago
    Michaël Vanbrabandt
    0

    Jhon,

    because you do:

     Model.Content.Descendants().Where(....)
    

    This returns a list.

    So your string caption should be done inside your foreach for each rejse of your nodes.

    /Michaël

  • Jhon 65 posts 138 karma points
    6 days ago
    Jhon
    0

    Fine. Thanks

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    6 days ago
    Michaël Vanbrabandt
    0

    No problem!

    Have a nice day!

    /Michaël

  • Jhon 65 posts 138 karma points
    6 days ago
    Jhon
    0

    Hi Michael,

    How to write two DocumentTypeAlias

    var node = Model.Content.Descendants().Where(x => x.DocumentTypeAlias == "PresseEkspert" || y => y.DocumentTypeAlias == "PresseForside" );

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    6 days ago
    Michaël Vanbrabandt
    0

    Hi Jhon,

    this way:

    var node = Model.Content.Descendants().Where(x => x.DocumentTypeAlias == "PresseEkspert" || x.DocumentTypeAlias == "PresseForside" );
    

    Also Jhon, is it possible to set the answer for this thread and make a new thread for another issue? Because this thread is getting big and contains many different issues.

    Hope this helps.

    /Michaël

  • Jhon 65 posts 138 karma points
    6 days ago
    Jhon
    0

    Sure. How can i mark the answer for this thread.

  • Michaël Vanbrabandt 725 posts 2876 karma points c-trib
    6 days ago
    Michaël Vanbrabandt
    0

    Hi Jhon,

    under the post that you find the most complete answer for your issue you have a button Mark as answer.

    Have a nice day!

    /Michaël

Please Sign in or register to post replies

Write your reply to:

Draft