I want to display the content of a Json file in a view in a project using ASP.NET MVC, but when i get the data and display it in a table in a view it looks like:
"data1data2data3data4"
How i can separate that JSON array of string with commas like:
"data1 , data2 , data3 , data4"
The JSON file has the next structure:
[
{
"Name":"Value",
"Name2":[
"Data1",
"Data2",
"Data3",
"Data4",
]
}
]
And i display the data in a table like:
<table border="1">
<thead>
<tr>
<th>Name</th>
<th>Name2</th>
</tr>
</thead>
<tbody>
@foreach (var element in Model)
{
<tr>
<td>@Html.DisplayFor(m => element.Name)</td>
<td>@Html.DisplayFor(m => element.Name2)</td>
</tr>
}
</tbody>
</table>
But it looks like:
Name | Name2
-----------------------------
Value | Data1Data2Data3Data4
and i want to display the data like:
Name | Name2
-----------------------------
Value | Data1 , Data2 , Data3 , Data4
Any way to do this?
Edit:
I have this method to get the Json data:
string fileJson = File.ReadAllText(@"Path.json");
var dataJson =
JsonConverter.DeserializeObject<List<Object>>(fileJson);
return dataJson;
And then called it from a controller