I am using Json.net for serializing and then making an JObject that looks like this:
\"RegistrationList\": [
{
\"CaseNumber\": \"120654-1330\",
I only want to display the CaseNumber, FirstName and Comment.
As always in ASP.NET MVC you could start by writing a view model that matches your requirements:
public class MyViewModel
{
public string CaseNumber { get; set; }
public string FirstName { get; set; }
public string Comment { get; set; }
}
then in your controller action you build the view model from the JObject instance you already have:
public ActionResult Index()
{
JObject json = ... the JSON shown in your question (after fixing the errors because what is shown in your question is invalid JSON)
IEnumerable model =
from item in (JArray)json["RegistrationList"]
select new MyViewModel
{
CaseNumber = item["CaseNumber"].Value(),
FirstName = item["Person"]["FirstName"].Value(),
Comment = item["User"]["Comment"].Value(),
};
return View(model);
}
and finally in your strongly typed view you display the desired information:
@model IEnumerable
Case number
First name
Comment
@foreach (var item in Model)
{
@item.CaseNumber
@item.FirstName
@item.Comment
}