Featured post
jquery - Pass HTML Table string through Json from controller to view -
i want achieve this:
public system.web.mvc.actionresult exposuregrid(guid? id, decimal stddev) { //return null; try { var str = "<table border=1>"; str += "<tr><th>date</th><th>expected credit exposure</th><th>max credit exposure</th></tr>"; str += "<tr><td>12/1/2010</td><td>100,000</td><td>50</td></tr>"; str += "<tr><td>12/2/2010</td><td>101,000</td><td>100</td></tr>"; str += "<tr><td>12/3/2010</td><td>102,000</td><td>150</td></tr>"; str += "<tr><td>12/4/2010</td><td>103,000</td><td>200</td></tr>"; str += "<tr><td>12/5/2010</td><td>104,000</td><td>250</td></tr>"; str += "<tr><td>12/6/2010</td><td>105,000</td><td>300</td></tr>"; str += "<tr><td>12/7/2010</td><td>106,000</td><td>350</td></tr>"; str += "</table>"; return json(str); } catch (exception e) { return json(e.tostring()); } }
then take json , put on view this:
$.ajax({ type: "post", url: "<%= url.action("exposuregrid", "indications") %> ", datatype: "jsondata", data: tablejson, success: function(data) { existingdiv = document.getelementbyid('table'); existingdiv.innerhtml = data; } });
but shows on view in html this:
"\u003ctable border=1\u003e\u003ctr\u003e\u003cth\u003edate\u003c/th\u003e\u003cth\u003eexpected credit exposure\u003c/th\u003e\u003cth\u003emax credit exposure\u003c/th\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/1/2010\u003c/td\u003e\u003ctd\u003e100,000\u003c/td\u003e\u003ctd\u003e50\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/2/2010\u003c/td\u003e\u003ctd\u003e101,000\u003c/td\u003e\u003ctd\u003e100\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/3/2010\u003c/td\u003e\u003ctd\u003e102,000\u003c/td\u003e\u003ctd\u003e150\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/4/2010\u003c/td\u003e\u003ctd\u003e103,000\u003c/td\u003e\u003ctd\u003e200\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/5/2010\u003c/td\u003e\u003ctd\u003e104,000\u003c/td\u003e\u003ctd\u003e250\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/6/2010\u003c/td\u003e\u003ctd\u003e105,000\u003c/td\u003e\u003ctd\u003e300\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e12/7/2010\u003c/td\u003e\u003ctd\u003e106,000\u003c/td\u003e\u003ctd\u003e350\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e"
how fix this?
change:
datatype: "jsondata",
to
datatype: "json",
hopefully, issue should resolved.
- Get link
- X
- Other Apps
Comments
Post a Comment