Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

view not found after update to 2.0 rtm #6680

Closed
@rynowak

Description

@rynowak

From @joeaudette on August 16, 2017 16:31

I have encountered a strange problem in the demo app for my pagination library after updating to 2.0 rtm

The problem can be seen in the netcore20 branch of this repository by running the PagingDemo.Web app:
https://github.com/joeaudette/cloudscribe.Web.Pagination

In Startup I have routes like this:

app.UseMvc(routes =>
        {
            routes.MapRoute(
               name: "pagingdemo1",
               template: "pager/{page:int?}"
               , defaults: new { controller = "Paging", action = "Index" }
               );

            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });

I have a PagingController with an Index action method, and the view exists at Views/Paging/Index.cshtml

My Index ActionMethod looks like this:

public IActionResult Index(int page = 1)
    {
        
        var currentPageNum = page;
        var offset = (DefaultPageSize * currentPageNum) - DefaultPageSize;
        var model = new ProductListViewModel();
        model.Products = this.allProducts
            .Skip(offset)
            .Take(DefaultPageSize)
            .ToList();

        model.Paging.CurrentPage = currentPageNum;
        model.Paging.ItemsPerPage = DefaultPageSize;
        model.Paging.TotalItems = allProducts.Count;

        
        return View(model);

        
    }

When you click the PagingDemo1 link in the navigation the url is http://localhost:55769/pager and it finds the Index view as it should. However when I click one of the pagination links which passes a parameter for the page number for example http://localhost:55769/pager/4

I get an error:

InvalidOperationException: The view 'Index' was not found. The following locations were searched:
/Views/Shared/Index.cshtml

So for some strange reason it in not looking in the right place for the view, it should look in Views/Paging but it only looks in Views/Shared

As I recall it worked fine in preview2 and it also worked in 1.x. No other code changes have been made except updating to 2.0 dependencies and making the Program.cs and Startup.cs more like what the latest project templates provide.

Copied from original issue: dotnet/aspnetcore#2134

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions