我在表中插入JSON字符串,而不是在foreach循环中的View中列出页面我想用Razor解析那个JSON字符串
@foreach (var item in Model) {
var pr = JsonConvert.DeserializeObject<dynamic>(item.profile);
//getting error
//the 'JsonConvert' does not exist in corrent context
//and also the return type Profile was showing error so I changed it to `dynamic`
<tr>
<td>@pr.Name</td>
}
当您的应用程序变大时,您会觉得使用Model-View-Controller的标准方法会更好。当时可能难以重新编码您的应用程序。您可以使用此方法:
如果您只是暂时测试某些内容,那么您可以在视图顶部添加@using Newtonsoft.Json
,以使其识别JsonConvert.DeserializeObject
方法。