Skip to content

Instantly share code, notes, and snippets.

@DylanCh
Created August 22, 2017 23:25
Show Gist options
  • Save DylanCh/0c5df884a532bc786d30c2c019c55a7c to your computer and use it in GitHub Desktop.
Save DylanCh/0c5df884a532bc786d30c2c019c55a7c to your computer and use it in GitHub Desktop.
// Route: /[Controller name]/Apple
public ContentResult Apple() {
var response = getResponse(); // get the deserilized object(or a list of objects)
StringBuilder html = new StringBuilder("<html><head>"
+ " <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\" >"
+ "</head><body class=\"container\">"
+ "<div class=\"row\">"
+ "<table class=\"table\">"
+ "<thead>"
+ "<tr>");
foreach (var th in response.Products[0].GetType().GetProperties()) {
html.Append(string.Format("<th>{0}</th>",th.Name));
}
html.Append("</tr></thead><tbody>");
foreach (var product in response.Products) {
html.Append(
string.Format("<tr><td>{0}</td><td>{1}</td></tr>",
product.name,
product.category));
}
html.Append("</tbody></table></body></html>");
return Content(html.ToString(), "text/html");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment