Copied to clipboard

Flag this post as spam?

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


  • Mathias Hove 3 posts 23 karma points
    Jun 11, 2015 @ 19:05
    Mathias Hove
    0

    Saving selectbox value after postback, and sorting view from the value.

    Hi . As mentioned in the title, i am trying to sort a foreach loop. I want the loop sorted from the selected value in the selectbox. Here is what i got, and its working. But is there a more correct way of doing this? - In my opinion this is a bit messy

     <form name="test" id="test" method="post">
            <select name="selectbox" id="selectValue">
    
                @foreach (var item in CurrentPage.AncestorOrSelf(1).FirstChild("Blog").Children.Where("Visible"))
                {
                    var Kategori = Request.Form["selectbox"];
                    var id = item.Id.ToString();
    
                    if (IsPost)
                    {
                        if (id == Kategori)
                        {
                            <option selected value="@item.Id">@item.Name</option>
                        }
                    }
                    if (id != Kategori)
                    {
                        <option value="@item.Id">@item.Name</option>
                    }
                }
            </select>
        </form>
        <div class="col-md-9">
            @*@Html.Partial("GetAllPosts")*@
    
            @{
                if (IsPost)
                {
    
                    var Kategori = Request.Form["selectbox"];
    
                    <h1></h1>
    
                    foreach (var item in Model.Content.Descendants("Posts").Where(p => p.Parent.Id.ToString() == Kategori))
                    {
                        @item.Name
                    }
                }
            }
        </div>
    

    I Am still very new to umbraco and programming in general, and abit unsecure of my solutions to the problems. :)

    Thankyou in advance.

    Mathias

  • 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