public class User
{
public string Name { get; set; }
public string Family { get; set; }
}
//List for send with tempData
var user = new List<User>()
{
new User(){Name = "Ali", Family = "Abbasi"},
new User(){Name = "Mohammad", Family = "Abbasi"},
new User(){Name = "Jhon", Family = "Abbasi"},
new User(){Name = "Danny", Family = "Abbasi"},
new User(){Name = "Mary", Family = "Abbasi"},
new User(){Name = "Hossien", Family = "Abbasi"}
};
using Newtonsoft.Json;
TempData["user"] = JsonConvert.SerializeObject(user);
using Newtonsoft.Json;
var tempdata = TempData["user"] as string; //Get tempData
var data = JsonConvert.DeserializeObject<List<User>>(tempdata); //Convert TempData to List
<!--Show Data-->
<table class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Family</th>
</tr>
</thead>
<tbody>
@{
foreach (var item in data)
{
<tr>
<td>@item.Name</td>
<td>@item.Family</td>
</tr>
}
}
</tbody>
<tfoot>
<tr>
<th>Name</th>
<th>Family</th>
</tr>
</tfoot>
</table>