I have 3 Kendo DropDownLists in a C# MVC application. The DropDownLists are responsible for security questions. All 12 questions are coming in from the datasource (db) and fed to these DropDownLists. The goal is to make each DropDownList display a subset of questions to the user ( 4 questions for each dropdown ) so as to avoid duplicate question options.
The Kendo Version used in this project: "2015.3.1111"
Here is the code for the 3rd DropDownList:
@(Html.Kendo().DropDownList()
.Name("QuestionID3")
.DataTextField("Question")
.DataValueField("QuestionID")
.HtmlAttributes(new { style = "width:500px", required = "required", validationMessage = "Question is required" })
.OptionLabel("--Select--")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetQuestions", "Home");
})
.ServerFiltering(false);
}))
I have tried the following proposed solution which failed to limit the data:
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetQuestions", "Home")
.Data("function() { return { take: 4 }; }");
})
I have also looked over the Kendo MVC documentation and attempted .Filter() as well as a few other solutions but it appears they may not be compatible with this version of Kendo UI.
Here is a solution I used ( there may be better ways ). I ended up modifying the 2nd & 3rd dropdown list to send a number to the server when getting the data and modifying the ActionMethod on the Controller to accept a int parameter named subSet (default: subSet=0).
In the View:
@(Html.Kendo().DropDownList()
.Name("QuestionID2")
.DataTextField("Question")
.DataValueField("QuestionID")
.HtmlAttributes(new { style = "width:500px", required = "required", validationMessage = "Question is required" })
.OptionLabel("--Select--")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetQuestions", "Home", new { subset = 1 });
})
.ServerFiltering(false);
}))
Keep in mind, it is 0 indexed so Question2 would send subset 1. I used a default parameter in my ActionMethod of subSet = 0. This is why I didn't need to modify the 1st DropDownList.
In the ActionMethod on the Controller:
I used the LINQ .Skip() & .Take() methods along with the subSet number received from the view to return the correct subset of questions ( 4 in my case ) back to each dropdown list. The code inside the ActionMethod for that looks like this:
int optionsAmount = 4;
var questionsSubList = listQuestions.Skip(subSet * optionsAmount).Take(optionsAmount);
return Json(questionsSubList, JsonRequestBehavior.AllowGet);
This