Copied to clipboard

Flag this post as spam?

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


  • umbracocool 108 posts 197 karma points
    Mar 22, 2013 @ 21:38
    umbracocool
    0

    To what use "Skip" in Razor?

    Hello friends. Actually I wonder what it does and if you have some examples thank you.

  • gary 385 posts 916 karma points
    Mar 23, 2013 @ 10:35
    gary
    100

    Hi

    To use skip() you then use take().

    @foreach (var item in CurrentPage.Children.Skip(2),Take(3))

    {<li>@item.Name<\li>}

    This will not show the first two child items, but will show child numbers 3, 4 and 5.

    If you want first child to display differently, use .Take(1),

    on another line  use .Skip(1).Take(3), this means you are making a list of 1, then list of children 2 to 4 under.

    @foreach (var item in CurrentPage.Children.Take(1))

    {<h2>@item.Name<\h2>}

    @foreach (var item in CurrentPage.Children.Skip(1),Take(3))

    {<li>@item.Name,<\li>}

    result;~

    CHILD NAME(1)

    childname(2),childname(3),childname(4)

    Hope it helps, have tried to explain in simple way

    G

  • Charles Afford 1163 posts 1709 karma points
    Mar 23, 2013 @ 16:58
    Charles Afford
    0

    Why would you actually need to use skip?  Charlie :)

  • umbracocool 108 posts 197 karma points
    Mar 23, 2013 @ 18:07
    umbracocool
    0

    Gary Thank you very much!.

    Charles permitirse  

    I want to use "Skip" to a page of results, I'm working and did not know exactly its functionality!

    Regards!

     

  • gary 385 posts 916 karma points
    Mar 23, 2013 @ 18:45
    gary
    0

    Hi Guys

    Umbracocool, thank you, glad it helped.

    Charlie I agree, you can use .First in the example above, but rather than use something a bit more complicated where the understanding of English may present a problem I thought simple was better. I really admire when someone whos first language is not English that can understand this stuff. As I live and work in Portugal I need to speak Portuguese, but when I am presented with Google Analytics in Portuguese, boy that's hard, it's hard enough at times in English to understand.

    I have used Skip when I wanted different image classes in a responsive design in a row of three.

    So first row of three has a sightly larger image, then take the next three, slightly smaller, then next three slightly smaller again.

    Dependent upon how you like to structure a page, you can use it for h tags, ie h2 at top of page, h3 further down.

    Again it may be possible to use .inGroupsOf(), but you still have to repeat it, so I guess it is just a question of preference.

    If you have a latest news page, that has 6 elements, you could have a link to all news which to avoid canonical links or repeating, you can skip the first six to show on the next page, the remainder of the list.

    I also used this to create an overlapping gallery with layers on separate z-index, just loaded the images into a damp gallery, took first three with absolute positioning, then took next three (with different crops) on a different z-index (or in different css class would be a better description) and absolutely positioned them for overlap. Using crops it meant that a user could shuffle the image order, but it would not break. Here I could not use inGroupsOf() because of the call to different crops.

    Hope that gives some idea of how it can be used, I'm sure there are more interesting uses, but we can only cover what is put in front of us.

    Regards G

  • Charles Afford 1163 posts 1709 karma points
    Mar 23, 2013 @ 19:18
    Charles Afford
    0

    Thanks Gary.  Thanks just never seen it used before.  I would expect the list to be generated in some abstraction, where in the View/partial you could just itterate thought the list and render the results :)  Charlie :)

  • umbracocool 108 posts 197 karma points
    Mar 23, 2013 @ 19:24
    umbracocool
    0

    By the way guys. Do you know of a very detailed handbook of Razor?

    A detailing manual of Razor MVC

    Regards!

  • Charles Afford 1163 posts 1709 karma points
    Mar 23, 2013 @ 19:38
    Charles Afford
    0

    http://msdn.microsoft.com/en-us/vs2010trainingcourse_aspnetmvc3razor.aspx  that is the msdn guide so that ought to be pretty good :)

Please Sign in or register to post replies

Write your reply to:

Draft