I am wanting to filter a list of Courses based on user input.
So initially I want the list to show all of the courses, then if a user clicks a button I want to pass the value to a variable which is being used in the where clause.
Below is the code which I have got at the moment, obviously I would add in the if statements depending on which button/option has been selected by the user, but if I am able to assign a user input to the variable I am sure I will be able to fill in the rest.
@{
var userInput = "Course Category A";
var course = CurrentPage.Site().FirstChild("coursesFolder").Children("course").Where("courseCategory == @0", @userInput).OrderBy("courseDate desc");
}
This is completely achievable without Umbraco Forms.
There are various options available to you, the first is to use some javascript to re-call your current page with a query string attached. You could then edit your view to process the query string.
Alternatively, you could use a surface controller to receive the input and then return the updated list. This could be called via ajax, or it could be a complete page reload.
Thanks for your advice. Do you have any example code similar to what I am trying to achieve with the query strings or know of any tutorials which may cover this?
Filtering a list Based on User Input
Hi,
I am wanting to filter a list of Courses based on user input.
So initially I want the list to show all of the courses, then if a user clicks a button I want to pass the value to a variable which is being used in the where clause.
Below is the code which I have got at the moment, obviously I would add in the if statements depending on which button/option has been selected by the user, but if I am able to assign a user input to the variable I am sure I will be able to fill in the rest.
@{ var userInput = "Course Category A"; var course = CurrentPage.Site().FirstChild("coursesFolder").Children("course").Where("courseCategory == @0", @userInput).OrderBy("courseDate desc"); }
@foreach(var item in course){-
@item.Name
@item.courseDate
}
Does anyone know how I would be able to achieve this? Or do I need Umbraco forms to to this?
Thanks in advance
Hi Kyle,
This is completely achievable without Umbraco Forms.
There are various options available to you, the first is to use some javascript to re-call your current page with a query string attached. You could then edit your view to process the query string.
Alternatively, you could use a surface controller to receive the input and then return the updated list. This could be called via ajax, or it could be a complete page reload.
Nik
Hi Nik,
Thanks for your advice. Do you have any example code similar to what I am trying to achieve with the query strings or know of any tutorials which may cover this?
Thanks for your help.
Hi Nik,
I think I have figured it out...
}
Thanks for your help!
is working on a reply...