Copied to clipboard

Flag this post as spam?

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


  • ketan italiya 17 posts 59 karma points
    May 12, 2014 @ 09:19
    ketan italiya
    0

    Need help for razor syntax in U7 Grid Data Type

    I use this code for razor syntax of U7 Grid Data Type,and also i use umbraco's version 7.1 in webmatrix

    ** razor example **
    <div>
        @foreach (var dog in CurrentPage.dogs)
        {
            <div>
                <p>Name - @dog.name </p>
                <p>Description - @Html.Raw(dog.description) </p>
                @if (dog.image != "") {
    
                    IPublishedContent iconImg = Umbraco.TypedMedia(dog.image.ToString());
                    <img src="@iconImg.Url" />
                }
                @if (dog.trained == "True")
                { 
                    <p>This dog is traind.</p>
                }
            </div>
        }
    </div>
    

    but i can't understand with this example what is currentpage.dogs here can you please help me or give me other example that how i use U7 Grid Data Type in my template page.Here my U7 Grid Data Type contain two column (image and description ).

    Thanks in advance.

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    May 12, 2014 @ 10:39
    Dennis Aaen
    0

    Hi ketan,

    I haven´t worked with U7 Grid Data Type, but CurrenPage is represents the page that you´re on in the content tree, and the CurrentPage.dogs, represents a property on the page with a alias of dogs.

    The documentation for working with properties, can be found here: http://our.umbraco.org/wiki/how-tos/working-with-document-types

    Documentation about what CurrentPage is in MVC can be found here:  http://our.umbraco.org/documentation/Reference/Mvc/views#Renderingafieldusing@CurrentPage%28dynamically%29

    Hope this can make your understanding more clear.

    /Dennis

  • ketan italiya 17 posts 59 karma points
    May 12, 2014 @ 11:54
    ketan italiya
    0

    Thanks Dennis for solution i used with this code but i got error.

    @foreach (var grid in @Model.Content.GetProperty("emprepater"))
    {
    <div>
    @if (grid.image != "")
     {
    IPublishedContent dogImage =Umbraco.TypedMedia(grid.image.ToString());
         <img src="@dogImage" />
    
    }
    <p>Description - @Html.Raw(grid.description) </p>
    
    
    </div>
    }
    </div>
    

    I mean when i am typing @Model then i press dot(.) then also fieldname(emprepater) which is created is not accessible.

    Can you give some suggestion or tips here.

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    May 12, 2014 @ 12:56
    Dennis Aaen
    0

    Hi ketan,

    The only thing that I can see right now is wrong is that you have a @ in front of Model.Content.GetProperty("emprepater") in the foreach loop, so try something like this.

    @foreach(var grid in Model.Content.GetProperty("emprepater"))
    {
    <div>
    @if(grid.image !="")
     
    {
    IPublishedContent dogImage = Umbraco.TypedMedia(grid.image.ToString());
         
    <img src="@dogImage"/>

    }
    <p>Description-@Html.Raw(grid.description)</p>


    div>
    }
    div>

    And your alias of the field that you want to get data from is named emprepater

    Hope this helps,

    /Dennis

  • ketan italiya 17 posts 59 karma points
    May 12, 2014 @ 13:34
    ketan italiya
    1

    Thanks for solution,with using your code i got this error.

    foreach statement cannot operate on variables of type 'Umbraco.Core.Models.IPublishedProperty' because 'Umbraco.Core.Models.IPublishedProperty' does not contain a public definition for 'GetEnumerator'

    enter image description here

    Can you help me for this?

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    May 12, 2014 @ 13:50
    Dennis Aaen
    0

    Hi ketan,

    Okay I will try to see if I could help you help out.

    How about something like this:

    <div>
        @foreach (var grid in CurrentPage.emprepater){
            <div>
            @if (grid.image != ""){
                IPublishedContent dogImage = Umbraco.TypedMedia(grid.image.ToString());
                    <img src="@dogImage" />
            }
           
            <p>Description - @Html.Raw(grid.description) </p>
        </div>
        }
    </div>

    And your alias of the field that you want to get data from is named emprepater

    Hope this helps,

    /Dennis

  • ketan italiya 17 posts 59 karma points
    May 12, 2014 @ 14:04
    ketan italiya
    0

    Thanks for quick reply Dennis this time it's work for me.but there is one small problem is there. Image is not displaying in website.Imagepath is wrong i think can you help me for this problem?

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    May 12, 2014 @ 14:28
    Dennis Aaen
    1

    Hi ketan,

    I think that I spotted what you´re missing. You´re missing url where you are printed the image.

    Try this:

    <div>
        @foreach (var grid in CurrentPage.emprepater){
           
    <div>
            @if (grid.image != ""){
                IPublishedContent dogImage = Umbraco.TypedMedia(grid.image.ToString());
                   
    <img src="@dogImage.Url"/>
            }
           
           
    <p>Description - @Html.Raw(grid.description) </p>
       
    </div>
        }
    </div>

    Hope this helps,

    /Dennis

  • ketan italiya 17 posts 59 karma points
    May 12, 2014 @ 14:36
    ketan italiya
    0

    Excellent Dennis This is completely work for me thanks for your support.I am really grateful of you.

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    May 12, 2014 @ 14:37
    Dennis Aaen
    0

    You´re welcome

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies