I have a .NET action which basically returns a set of JSON results like this:
return Json(new
{
lineData = groupedByDate,
// more properties returned here...
dataForTable = View("Index") // note this one
}, JsonRequestBehavior.AllowGet);
Before the return function I set up the data source for my ViewBag which is the source of data for my table in HTML like this:
ViewBag.Items = items.ToList();
And in my view:
<table id="tableProducts" class="table table-striped table-hover table-fw-widget">
<tbody>
@if (ViewBag.Items != null)
{
foreach (var item in ViewBag.Items)
{
<tr>
<td>@item.Title//for example</td>
</tr>
}
}
</tbody>
</table>
And here is the part that's not working for me... I'm actually setting up the json values in my .done method from post like this:
($.post...).done(function(data){
graph.SetData(data.lineData); // this is fine
And now I would like to simply inject the returned view here as well in the DOM.. Like this:
var products= $('<table />').append(data.dataForTable).find('#tableProducts').html();
$('#tableProducts').html(products);
});
And so this is the problem:
var products= $('<table />').append(data.dataForTable).find('#tableProducts').html();
$('#tableProducts').html(products);
I'm expecting to inject the returned part of the view into the DOM but nothing happens when I do this... The table is still empty as it was in the beginning...
What am I doing wrong here?