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

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

Activity

  1. rynowak commented on Aug 17, 2017

    @rynowak
    ContributorAuthor

    From @davidfowl on August 16, 2017 17:32

    Change the page variable name to p in the route definition and method. See if that works.
    I believe we have an unintentional breaking change here

  2. rynowak commented on Aug 17, 2017

    @rynowak
    ContributorAuthor

    From @joeaudette on August 16, 2017 17:43

    @davidfowl I confirm that changing the variable to p solved it

  3. rynowak commented on Aug 17, 2017

    @rynowak
    ContributorAuthor

    From @joeaudette on August 16, 2017 17:44

    @davidfowl but doing that also changed the url from http://localhost:55769/pager/4 to http://localhost:55769/pager?page=4

    which wasn't desired

  4. rynowak commented on Aug 17, 2017

    @rynowak
    ContributorAuthor

    From @davidfowl on August 16, 2017 18:4

    There's another work around but that shouldn't happen with this one. Did you update the method parameter as well?

  5. rynowak commented on Aug 17, 2017

    @rynowak
    ContributorAuthor

    From @joeaudette on August 16, 2017 18:8

    ok, changing the method param and the asp-route param to p as well solved it and kept the desired url structure

  6. rynowak commented on Aug 17, 2017

    @rynowak
    ContributorAuthor

    I'm moving this to the MVC repo where we can track the fix for this on our side. We don't intend for the 'pages' view search behavior to kick in unless you are using pages.

  7. eat-sleep-code commented on Aug 17, 2017

    @eat-sleep-code

    FYI this has been logged as a bug: #6660

  8. pranavkm commented on Aug 24, 2017

    @pranavkm
    Contributor

    Yup @eat-sleep-code , this is a dup of #6600. Closing this since we've other work items tracking for the patch and 2.1.0 releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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