In a strongly-typed list-view, I am trying to pass the current data on (as a list of the model) to my controller via Ajax, so it can do something with it.
The problem I am facing, is that I cannot seem to pass the list of data in the current view to my controller. Using the AJAX method without parameter works (but I need to use the parameter, or if there is some other way to provide said information to my controller?).
I have also tried making a list (test) when the view is being constructed and then using that variable as a parameter but apparently after construction the variable is empty?
Index view
@model IEnumerable<databaseModel.cbms>
@{
ViewBag.Title = "Cbms Home";
List<databaseModel.cbms> test = Model.ToList();
}
@Ajax.ActionLink("productId", "AJX_SortByProductId", new { cbmsModel = test }, new AjaxOptions()
{
HttpMethod = "GET",
UpdateTargetId = "divCbms",
InsertionMode = InsertionMode.Replace
})
Controller
public PartialViewResult AJX_SortByProductId(List<cbms> cbmsModel)
{
//Retrieves the data
List<cbms> model = cbms.SortByProductId();
//Returns the partial view
return PartialView("_Cbms", model);
}
So, when I get into the controller, the List cbmsModel is empty and I cannot use it as a parameter. I can pass on a string with no problem, but I want a list of the current model data on my view.
EDIT:
The following also does not work:
Model
@model IEnumerable<databaseModel.cbms>
@{
ViewBag.Title = "Cbms Home";
List<databaseModel.cbms> test = Model.ToList();
List<databaseModel.cbms> cbmsModel = new List<databaseModel.cbms>();
int i = 0;
foreach (databaseModel.cbms value in test)
{
i++;
TempData.Add(i.ToString(), value);
}
}
@Ajax.ActionLink("productId", "AJX_SortByProductId", new { cbmsModel = TempData.Values.ToList() }, new AjaxOptions()
{
HttpMethod = "GET",
UpdateTargetId = "divCbms",
InsertionMode = InsertionMode.Replace
})
This still results in the parameter being empty. I really do not get why...