MVC视图显示无意义数据

时间:2017-04-07 16:26:59

标签: c# asp.net-mvc entity-framework gzip tolist

最近我遇到了一个Index视图的问题。该页面显示为此图像链接Result of UserManager.Users.ToListAsync()中的无意义数据。这才刚刚开始,但不确定原因。对此的任何帮助都会很棒!

代码非常简单:

public virtual async Task<ActionResult> Index()
{
    return View(await UserManager.Users.ToListAsync());
}

视图

@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);
}

0 个答案:

没有答案