I encountered a problem as described in the topic.
I use dropDownList from Kendo UI
http://demos.telerik.com/aspnet-mvc/dropdownlist/serverfiltering
that connects with the dataSource(data from database) with Ajax.
Now the dropdownList is getting the data without any problems if I place the method in the same controller as the view. But at first it was placed in another controller and I was getting the data only if I initialized that controller in some other view.
Here is the method:
public ActionResult GetGroups()
{
var list = new List<string>();
foreach (var item in _repositorySpisGrup.Select())
{
list.Add(item.Nazwa);
}
return Json(list, JsonRequestBehavior.AllowGet);
}
Could anyone tell me why that is ?
And to avoid this problem where should I put my action method that may be called from many different views ?
Cheers!
EDIT :
Code for the dropdown (placed in partialView):
@(Html.Kendo().DropDownList()
.Name("Group")
.Value(Model.Group)
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetGroups", ViewContext.RouteData.GetRequiredString("controller"));
})
.ServerFiltering(true);
})
)
Like I said this is a working code because I copied the Action method to the same controller as the view. The problem is when I take Json data from another controller.
read.Action("GetGroups", "Controller2");
? Verify your ajax request with Fiddler. – nZeus