Recently I came across an issue with an Index view. The page displays as nonsense data as seen in this image link, Result of UserManager.Users.ToListAsync(). This just start happening but not sure why. Any help on this would be amazing!
The code is pretty simple:
public virtual async Task<ActionResult> Index()
{
return View(await UserManager.Users.ToListAsync());
}
The View
@model IEnumerable<SafeWare.Models.Identity.ApplicationUser>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.UserName)
</th>
<th>
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.UserName)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
@Html.ActionLink("Details", "Details", new { id = item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Id })
</td>
</tr>
}
</table>
OnActionExecuting
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
bool allowCompression = true;
//bool.TryParse(ConfigurationManager.AppSettings["Compression"], out allowCompression);
if (allowCompression)
{
HttpRequestBase request = filterContext.HttpContext.Request;
string acceptEncoding = request.Headers["Accept-Encoding"];
if (string.IsNullOrEmpty(acceptEncoding)) return;
acceptEncoding = acceptEncoding.ToUpperInvariant();
HttpResponseBase response = filterContext.HttpContext.Response;
if (acceptEncoding.Contains("GZIP"))
{
response.AppendHeader("Content-encoding", "gzip");
response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
}
else if (acceptEncoding.Contains("DEFLATE"))
{
response.AppendHeader("Content-encoding", "deflate");
response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
}
}
base.OnActionExecuting(filterContext);
}