My problem seems very common tio me, and I thought I can find my answer online, but I couldn't. I have a drop down list, and based on the selected value, I need to have multiple partial Views. (one selection can have none, the other one have 3, etc.)
I have a partial View that gets a "DriveDetail" object.
I need to load multiple number of these partial Views Dynamically using JQuery.
So far I have
$.ajax({
url: "TestInput/getTestStationInformation2/" + testStation,
dataType: "json",
type: 'post',
success: function(data) {
for (var i = 0; i < data.length; i++) {
$('#driveDetailDiv').append(data[i]);
}
}
});
I can either return an IEnumerable or List of those Drives.
public JsonResult getTestStationInformation(long id)
{
IEnumerable<DriveDetails> aa = repository.listDriveInfo(id);
return Json(aa);
}
public JsonResult getTestStationInformation2(long id)
{
List<PartialViewResult> res = new List<PartialViewResult>();
List<DriveDetails> aa = repository.listDriveInfo(id).ToList();
for (int i = 0; i < aa.Count(); i++)
{
res.Add(PartialView("DriveDetailsPartial", aa[i]));
}
return Json( res);
}
but none of these work.
I have
$.get('<%= Url.Action("Details","TestInput", null) %>', function(tmp) {
$('#driveDetailDiv').append(tmp);
});
in my code, but instead of null, I need to send data[0], and get the partialView of data[0]. but I don't know how to send data[0]. When I try
new {id = data[0])
I get an error.
and When I try to use the second Action which returns a list of partialViews, it doesn't show up when I try to append them.