Copied to clipboard

Flag this post as spam?

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


  • Jhon 87 posts 162 karma points
    Apr 04, 2018 @ 13:01
    Jhon
    0

    Hi,

    I have written this code here /Views/Partials/undervisningLeft.cshtml

    why is getting error.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    
    var node = Model;
    
        foreach(var text in node.Children) {
            <div class="module">
                <h2>@text.title</h2>
                <p>@text.bodyText</p>
            </div>
            <div style="clear: both;"></div>
        }
    

    now i got 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 'text' does not exist in the current context

    Source File: c:\Users\Malar\Desktop\deo7.8.1\Views\Partials\undervisningLeft.cshtml Line: 9

  • Jules 269 posts 560 karma points
    Apr 04, 2018 @ 13:17
    Jules
    0

    The first issue seems to be var node = Model which should be:

    var node = Model.Content;
    

    Additionally, as you are not dealing with strongly typed content, you cannot directly access the property values using the syntax you are using. Each item in node.Children is an IPublishedContent item which has no idea what title and bodyText are. You would have to use GetPropertyValue("myPropertyName") to get the property values you require.

    This should work:

    foreach(var text in node.Children) 
    {
        <div class="module">
            <h2>@text.GetPropertyValue("title")</h2>
            <p>@text.GetPropertyValue("bodyText")</p>
        </div>
        <div style="clear: both;"></div>
    }
    

    Jules

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 04, 2018 @ 13:23
    Michaël Vanbrabandt
    0

    Hi John,

    use this:

    var node = Model.Content;
    

    instead of

    var node = Model;
    

    Hope this helps!

    /Michaël

  • Jhon 87 posts 162 karma points
    Apr 04, 2018 @ 13:40
    Jhon
    0

    Ok , I have written like that,

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    var node = Model.Content;

     foreach(var text in node.Children)  {
        <div class="module">
            <h2>@text.GetPropertyValue("title")</h2>
            <p>@text.GetPropertyValue("bodyText")</p>
        </div>
        <div style="clear: both;"></div>
    

    But it is getting same error.

    enter image description here

  • Jules 269 posts 560 karma points
    Apr 04, 2018 @ 13:48
    Jules
    0

    Are you using Visual Studio? Can you debug?

    Maybe try tidying up a bit first. Above snippet is missing closing brace on foreach as well:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        var node = Model.Content;
    }
    
    @foreach (var text in node.Children)
    {
        <div class="module">
            <h2>@text.GetPropertyValue("title")</h2>
            <p>@text.GetPropertyValue("bodyText")</p>
        </div>
        <div style="clear: both;"></div>
    }
    
  • Jhon 87 posts 162 karma points
    Apr 05, 2018 @ 07:21
    Jhon
    0

    Hi jules,

    Thank you so much for your help. I am a student, now i am learning Umbraco. It helps me a lot .

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 05, 2018 @ 07:25
    Michaël Vanbrabandt
    0

    Hi Jhon,

    if you really want to learn Umbraco then have a look at the documentation which is getting better and better these days:

    https://our.umbraco.org/documentation/

    Also another good source is https://umbraco.tv/ which contains lot of videos of how to do things in Umbraco.

    Have a nice learning experience with Umbraco and don't forget, if you have questions don't hesitate to ask them on the forum!

    Hope this helps!

    /Michaël

  • Jhon 87 posts 162 karma points
    Apr 05, 2018 @ 08:51
    Jhon
    0

    Hi,

    It works fine below coding.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ var node = Model.Content; }

    @foreach (var text in node.Children)

    {

    @text.GetPropertyValue("titleBox")

    @text.GetPropertyValue("linksText")

    </div>
    

    }

    Using the same output , i have written in another way , Why is it not working?

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    var boxes = Model.Children.Where("NodeTypeAlias == \"undervisningBox\"");
    
    
    
        foreach (var box in boxes) {
            <div class="box">
                <h4>@box.GetPropertyValue("titleBox")</h4>
                @box.GetPropertyValue("linksText")
            </div>
        }
    

    I am getting error.

    enter image description here

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 05, 2018 @ 08:56
    Michaël Vanbrabandt
    0

    Hi Jhon,

    try the following:

    var boxes = Model.Children.Where(x => x.DocumentTypeAlias == "undervisningBox");
    

    Hope this helps!

    /Michaël

  • Jhon 87 posts 162 karma points
    Apr 05, 2018 @ 08:58
    Jhon
    0

    No, It is not working. The same error is coming.

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 05, 2018 @ 09:10
    Michaël Vanbrabandt
    0

    Hi Jhon,

    can you show us the complete code snippet of your partial view because now you are missing braces.

    Should be something like below:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        var boxes = Model.Content.Children.Where(x => x.DocumentTypeAlias == "undervisningBox");
    }
    
    @foreach (var box in boxes)
    {
        <div class="box">
            <h4>@box.GetPropertyValue("titleBox")</h4>
            @box.GetPropertyValue("linksText")
        </div>
    }
    

    Thanks

    /Michaël

  • Jhon 87 posts 162 karma points
    Apr 05, 2018 @ 09:16
    Jhon
    0

    Yes, i tried , it is getting .

    enter image description here

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 05, 2018 @ 09:20
    Michaël Vanbrabandt
    0

    Hi Jhon,

    had a typo it has to be:

    var boxes = Model.Content.Children.Where(x => x.DocumentTypeAlias == "undervisningBox");
    

    Forgot the .Content part ( writing without compiler ).

    Hope this helps!

    /Michaël

  • Jhon 87 posts 162 karma points
    Apr 05, 2018 @ 09:28
    Jhon
    1

    Thank you so much, it works fine. I can understand umbraco flow part, now i am trying coding part . Thank you for your help.

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 05, 2018 @ 09:31
    Michaël Vanbrabandt
    0

    Hi Jhon,

    no problem that's why we are here for at the community!

    Keep on learning Umbraco using the links I mentioned of the documentation and umbraco.tv!

    Have a nice day and enjoy Umbraco!

    /Michaël

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 05, 2018 @ 09:45
    Michaël Vanbrabandt
    0

    Hi Jhon,

    don't forget to accept the answer which solved your problem. By doing this others with the same problem can directly view the correct solution.

    Thanks and have a nice day

    /Michaël

  • Jhon 87 posts 162 karma points
    Apr 05, 2018 @ 10:04
    Jhon
    0

    Hi,

    Why is the code getting error .

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @{ var projekter = Model.Content; }

    @foreach(var projekt in projekter.Children) {
    
        <div class="col-md-4">
            <div class="wrapper">
                <div class="card radius shadowDepth1">
    
                <a href="@projekt.Url">
                        <div class="card__image border-tlr-radius">
                            @if (projekt.HasValue("image")) {
                                var media = Library.MediaById(@projekt.GetPropertyValue("image"));
                                <img src="@media.umbracoFile" alt="image" class="border-tlr-radius" />
                            }
                        </div>
                    </a>
    
                    <article class="card__article">
                        <h2><a href="@projekt.Url">@projekt.GetPropertyValue("titel")</a></h2>
                        <a href="@projekt.Url"><p>@projekt.GetPropertyValue("teaser")</p></a>               
                    </article>
    
    
                </div>
            </div>
        </div>
    
    }   
    

    dggfsdf enter image description here

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 05, 2018 @ 10:08
    Michaël Vanbrabandt
    0

    Hi Jhon,

    The Library is not known, which version of Umbraco are you using?

    Please have a look at these docs about getting the image from a Media Picker:

    https://our.umbraco.org/documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Media-Picker2

    Hope this helps.

    /Michaël

  • Jhon 87 posts 162 karma points
    Apr 05, 2018 @ 10:12
    Jhon
    0

    I am using umbraco 7.8.1

  • Jhon 87 posts 162 karma points
    Apr 06, 2018 @ 08:12
    Jhon
    0

    Hi

    I tried image , it is not displaying image but it is passing image id. Can you see and what is the mistake.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @{ var projekter = Model.Content; }

    @foreach(var projekt in projekter.Children) {
    
        <div class="col-md-4">
            <div class="wrapper">
                <div class="card radius shadowDepth1">
    
    
    <a href="@projekt.Url">
    <div class="card__image border-tlr-radius">
    @{
    
    var typedMultiMediaPicker = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("image");
    
        <img src="@projekt.GetPropertyValue("image")" style="width:200px"/>
    

    }

                    <article class="card__article">
                        <h2><a href="@projekt.Url">@projekt.GetPropertyValue("titel")</a></h2>
                        <a href="@projekt.Url"><p>@projekt.GetPropertyValue("teaser")</p></a>               
                    </article>
    
    
                </div>
            </div>
        </div>
    
    }   
    

    see out put

    enter image description here

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 06, 2018 @ 08:30
    Michaël Vanbrabandt
    0

    Hi Jhon,

    look at the example in the docs: https://our.umbraco.org/documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Media-Picker2#typed-example-multiple-enabled

    You can see that for the source of the image you just can use:

     <img src="@typedMultiMediaPicker.Url" style="width:200px" />
    

    Hope this helps!

    /Michaël

  • Jhon 87 posts 162 karma points
    Apr 06, 2018 @ 08:55
    Jhon
    0

    Yes , i looked at the example in the docs. I am little bit confused about img src . I used before it is getting error.

    enter image description here

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 06, 2018 @ 09:10
    Michaël Vanbrabandt
    0

    Hi Jhon,

    that's because you enabled the Multi selection of the picker. So your typedMultiMediaPicker contains a list of images.

    You need to loop over these images using a foreach, if you only want one image then you can change the property to disable multi selection and then change your code to:

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

    Now it contains only one image.

    Hope this helps!

    /Michaël

  • Jhon 87 posts 162 karma points
    Apr 06, 2018 @ 09:34
    Jhon
    0

    yes , i disabled .

    enter image description here

    I have changed code. it is getting error.

    enter image description here

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 06, 2018 @ 09:39
    Michaël Vanbrabandt
    0

    Hi Jhon,

    could you add a null check to see if you really have an image:

    if (typedMediaPickerSingle != null)
    

    /Michaël

  • Jhon 87 posts 162 karma points
    Apr 06, 2018 @ 09:58
    Jhon
    0

    If i add like that ,

    @{ var typedMultiMediaPicker = Model.Content.GetPropertyValue

    <img src="@typedMultiMediaPicker.Url" style="width:200px" />
     }   
    

    }

    Is not displaying image , Title and teaser is displaying . see output.

    enter image description here

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 06, 2018 @ 10:02
    Michaël Vanbrabandt
    0

    Jhon,

    can you confirm that you picked an image with the Media Picker on the content node?

    /Michaël

  • Jhon 87 posts 162 karma points
    Apr 06, 2018 @ 10:05
    Jhon
    0

    Yes i am sure . see belowenter image description here

  • Jhon 87 posts 162 karma points
    Apr 06, 2018 @ 10:07
    Jhon
    0

    yes i am sure that i picked an image with the Media on the content node.

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 06, 2018 @ 10:09
    Michaël Vanbrabandt
    0

    What is the alias of your Billede property? Because you set image as the property Alias for taking the image. Shouldn't it be:

    var typedMultiMediaPicker = Model.Content.GetPropertyValue<IPublishedContent>("billede");
    

    Hope this helps!

    /Michaël

  • Jhon 87 posts 162 karma points
    Apr 06, 2018 @ 10:11
    Jhon
    0

    No, The proberty alias is image

    enter image description here

Please Sign in or register to post replies

Write your reply to:

Draft