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. :)
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
I Am still very new to umbraco and programming in general, and abit unsecure of my solutions to the problems. :)
Thankyou in advance.
Mathias
is working on a reply...