【发布时间】:2016-08-24 15:59:29
【问题描述】:
我正在使用来自 .net 的 MVC 模板,我可以显示我的 json,但现在我想将其解析为 html,最好是在表格中,这样看起来会更好。
我从 HomeController.cs 获取 json 到我的 View,即 About.cshtml,但它只是 json 字符串,所以看起来很糟糕。
public class HomeController : Controller
{
public JsonResult TestJson()
{
var client = new WebClient();
var response = client.DownloadString(new Uri("http://localhost:8080/projecten/api/leerlingen"));
var someObject = JsonConvert.DeserializeObject(response);
return new JsonResult() { Data = someObject, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
public ActionResult About()
{
var client = new WebClient();
var json = client.DownloadString(new Uri("http://localhost:8080/projecten/api/leerlingen"));
//parse json
ViewBag.Message = json;
return View();
}
}
这是json
[{"inschrijvingsNummer":"0001","naam":"John Smith","email":"john.smith@example.com","evaluatieNummer":"270"},
{"inschrijvingsNummer":"0002","naam":"Joe Bloggs","email":"joe.bloggs@example.com","evaluatieNummer":"370"}]
使用 .net 转换为 html 我在此页面中显示 (About.cshtml)
@{
ViewBag.Title = "Evaluaties";
}
<h2>@ViewBag.Title.</h2>
<p>@ViewBag.Message</p>
【问题讨论】:
-
@Shyju 作为桌子会更好看
-
我发布了一个答案。
标签: c# html .net json asp.net-mvc