I have an MVC application and I would like to pass an html table from the controller to the view using json.
I found this Q&A in this site: Sending HTML Code Through JSON which recommends json_encode but it's for PHP and I'm using C#...
How can I pass an HTML Table using Json?
Currently I tried:
return Json(MyHTMLTable);
In my view:
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
url: '@Url.Action("GetTable","MyPages")',
type: 'POST',
success: function (result) { $('#ph').html(result.responseText); },
error: function (result) {
$('#err').html(result.responseText);
}
})
});
(ph is a div)
I got the following error: A circular reference was detected while serializing an object of type 'System.Web.UI.WebControls.TableRow'.