c# - Linq query JObject -


i using json.net serializing , making jobject looks this:

 "registrationlist": [     {       "casenumber": "120654-1330",       "priority": 5,       "personid": 7,       "person": {         "firstname": "",         "lastname": "",       },       "userid": 7,       "user": {         "id": 7,         "createdtime": "2013-07-05t13:09:57.87",         "comment": "",     }, 

how query new object or list, put html table/view. want display casenumber, firstname , comment.

i want display casenumber, firstname , comment.

as in asp.net mvc start writing view model matches requirements:

public class myviewmodel {     public string casenumber { get; set; }     public string firstname { get; set; }     public string comment { get; set; } } 

then in controller action build view model jobject instance have:

public actionresult index() {     jobject json = ... json shown in question (after fixing errors because shown in question invalid json)      ienumerable<myviewmodel> model =         item in (jarray)json["registrationlist"]         select new myviewmodel         {             casenumber = item["casenumber"].value<string>(),             firstname = item["person"]["firstname"].value<string>(),             comment = item["user"]["comment"].value<string>(),         };      return view(model); } 

and in typed view display desired information:

@model ienumerable<myviewmodel>  <table>     <thead>         <tr>             <th>case number</th>             <th>first name</th>             <th>comment</th>         </tr>     </thead>     <tbody>         @foreach (var item in model)         {             <tr>                 <td>@item.casenumber</td>                 <td>@item.firstname</td>                 <td>@item.comment</td>             </tr>         }     </tbody> </table> 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -