joeharrison714 / MVCGrid.Net

http://mvcgrid.net
MIT License
74 stars 55 forks source link

Column sort images are broken links with ERR_CONNECTION_RESET in console #14

Open johnpreed opened 9 years ago

johnpreed commented 9 years ago

I keep getting broken image links for the sort column image in Chrome. In the developer console i'm seeing:

Failed to load resource: net::ERR_CONNECTION_RESET http://myurl/MVCGridHandler.axd/sort.png

also the same error for the ajaxloader.gif. if i browse to the image url manually, i can see the image. in IE this is not an issue. in chrome it was fine for a while and as i was working in visual studio, it suddenly started happening. when it would happen, i'd close chrome and relaunch and the images would show up. now that doesn't seem to fix the issue. not sure of the exact repro here. I have 3 grids in my project and it happens for all of them.

Here's one of the grid configurations:

MVCGridDefinitionTable.Add("ProjectsGrid", new MVCGridBuilder<ProjectSummaryViewModel>()
    .WithAuthorizationType(AuthorizationType.AllowAnonymous)
    .WithAdditionalQueryOptionNames("f", "k", "c", "cop")
    .AddColumns(cols =>
    {
        cols.Add("IsFavorite")
            .WithSorting(false)
            .WithHeaderText("")
            .WithValueExpression(p => p.IsFavorite ? "glyphicon glyphicon-star" : "glyphicon glyphicon-star-empty")
            .WithValueTemplate("<a class='hover-link' onclick='javascript:setFavorite(\"{Model.IsFavorite}\", {Model.ProjectId})'><span class='{Value}'></span></a>", false)
            .WithPlainTextValueExpression(p => p.IsFavorite.ToString());
        cols.Add("ProjectNumber")
            .WithHeaderText("Project #")
            .WithSorting(true)
            .WithValueExpression((p, c) => c.UrlHelper.Action("Edit", "Projects", new {id = p.ProjectId}))
            .WithValueTemplate("<a href='{Value}'>{Model.ProjectNumber}</a>", false)
            .WithPlainTextValueExpression(p => p.ProjectNumber);
        cols.Add("ProjectName")
            .WithSorting(true)
            .WithHeaderText("Project Name")
            .WithValueExpression(p => p.ProjectName);
        cols.Add("CreatedDate")
            .WithSorting(true)
            .WithHeaderText("Date Created")
            .WithValueExpression(p => p.CreatedDateLocal.ToString("MM/dd/yyyy hh:mm tt"));
        cols.Add("ProjectManagersDelimited")
            .WithSorting(false)
            .WithHeaderText("Project Manager")
            .WithValueExpression(p => p.ProjectManagersDelimited);
        cols.Add("OpenItems")
            .WithHeaderText("Open Items")
            .WithSorting(true)
            .WithValueExpression((p, c) => c.UrlHelper.Action("Index", "Items", new { projectId = p.ProjectId, s = Config.ItemStateNames.Open }))
            .WithValueTemplate("<a href='{Value}'>{Model.OpenItems}</a>", false)
            .WithPlainTextValueExpression(p => (p.OpenItems.HasValue ? p.OpenItems.Value : 0).ToString(CultureInfo.InvariantCulture));
        cols.Add("TotalReports")
            .WithSorting(true)
            .WithHeaderText("Total Reports")
            .WithValueExpression(p => p.TotalReports.ToString(CultureInfo.InvariantCulture));
        cols.Add("Reports").WithHtmlEncoding(false)
            .WithSorting(false)
            .WithHeaderText(" ")
            .WithValueExpression((p, c) => c.UrlHelper.Action("Index", "Reports", new { id = p.ProjectId }))
            .WithValueTemplate("<a href='{Value}' class='btn btn-default btn-sm' role='button'>Reports</a>");
    })
    .WithSorting(true, "ProjectId", SortDirection.Dsc)
    .WithPaging(true, 10)
    .WithFiltering(true)
    .WithRowCssClassExpression(p => p.IsFavorite ? "success" : String.Empty)
    .WithRetrieveDataMethod(context =>
    {
        var options = context.QueryOptions;
        int totalRecords;

        var userId = context.CurrentHttpContext.User.Identity.GetUserId();
        var items = ProjectManager.GetProjectGridPage(out totalRecords, options, userId);

        return new QueryResult<ProjectSummaryViewModel>
        {
            Items = items.TryToList(),
            TotalRecords = totalRecords
        };
    })
);