c# Asp net core 3.1 with Razor Pages redirects to the Index page instead of the intended page

Find centralized, trusted content and collaborate around the technologies you use most. To see the code in action, open the solution in Visual Studio 2019 and run the NetLearner.Blazor project. A new major release of .NET is published every year in November, enabling developers, the community, and businesses to plan their roadmaps.

  • ASP.NET Core is an open source web-development framework for building web apps on the .NET platform.
  • In both cases, learning C# as a language and ASP.NET Core as a framework will tick those boxes.
  • Move your SharedResources.cs to a different location I cloned you project and moved it to the Localization folder and it worked.

The key difference between Razor Pages implementation of the MVC pattern and ASP.NET Core MVC is that Razor Pages uses the Page Controller pattern instead of the Front Controller pattern. Donations to freeCodeCamp go toward our education initiatives, and help pay for servers, services, and staff. In the sample project, browsing to the ResourceLists page with the search string “videos” includes any search results that include the term “videos”, as shown in the following screenshot. Page parameters can be included with the @page directive at the top of the page. You may also couple the parameter names with a data type, e.g. int for integers. To use the Model’s properties, you can use the syntax Model.Property to refer to each property by name.

B is for Blazor Full-Stack Web Dev

Instead of using the name of the model, you have to use the actual word “Model” in your Razor Page code. This may come in handy when passing in QueryString parameters to be consumed by your Razor Page. Parameters are optional and are part of the route used to access your Razor Pages. Note that [BindProperty] allows you to bind properties for HTTP POST requests by default.

ASP.NET Core 3.1 Razor Lessons

Even numbered releases are LTS releases with free support and patches for three years. Odd-numbered releases are STS releases with free support and patches for 18 months. Razor Pages were introduced in ASP .NET Core v2.0, and briefly covered in my 2018 series, and with more detail in my 2019 A-Z series. To complement this updated post in 2020, you may also refer to a previous posts in this series to learn more about Forms and Fields (specifically the Razor Pages section). First of all, make sure that the Index page is within the same controller as the OnGetAsync method. If not, I would recommend to use the RedirectToAction(«Action», «Controller»);.

Rendering the Application

Built on top of MVC in ASP .NET Core, Razor Pages allows you to simplify the way you organize and code your web apps. Your Razor Pages may coexist along with a backend Web API and/or traditional MVC views backed by controllers. Razor Pages are typically backed by a corresponding .cs class file, which represents a Model for the Page with Model Properties and Action Methods that represent HTTP Verbs. You can even use your Razor knowledge to work on Blazor fullstack web development.

This can be accomplished by including an optional boolean parameter (SupportsGet) and setting it to True, e.g. This is reflected in the Solution Explorer, where the Dependencies tree may show NewtonsoftJson and/or EF Core packages nested under the NuGet node, if you use them in your project.

ASP.NET Core Basics

The framework is a complete rewrite from scratch to make it open-source, modular, and cross-platform. These ASP.NET Core Tutorials are designed for Beginners and Professional Developers who want to learn ASP.NET Core step by step. Here, in these .NET Core Tutorials, we will provide a hands-on approach to the subject with step-by-step ASP.NET Core 3.1 Razor Lessons program examples that will assist you in learning and putting the acquired knowledge into practice. Master ASP.NET Core Razor 3.1 course is designed for those who are interested in learning the most latest framework Microsoft has introduced. This is a complete course that will take you from basics all the way to advanced mode.

Note that the DataChanged() method includes some asynchronous calls to Get() methods from a service class. These are the service classes in the shared library that are also used by the MVC and Razor Pages web apps in NetLearner. Note that the Startup class doesn’t have to be called Startup, but you do have to tell your application what it’s called. Instead, you just need a call to AddServerSideBlazor() in ConfigureServices() and a call to MapBlazorHub() in Configure() while setting up endpoints with UseEndPoints(). Razor Pages is the default for building server-side web applications in ASP.NET Core. Components within the underlying MVC framework still have their uses such as using controllers for building RESTful APIs.

The StateHasChanged() method can be called manually to rerender the component, e.g. when an item is added/edited/deleted in the UI. Razor Pages is suitable for all kinds of developers from beginners to enterprise level. In this ASP.NET Core Tutorials series, I will discuss all the basic, intermediate, and advanced concepts of ASP.NET Core (.NET 6).

ASP.NET Core 3.1 Razor Lessons

Henrik Mühlbradt

Henrik har testet sykler og utstyr for ulike publikasjoner siden 2006, og er sammen med Morten Iversen blant de mest erfarne sykkeltesterne i Norge. Henrik er opptatt av alle former for sykling, men har en forkjærlighet for terrengsykling og cyclocross. Han har konkurrert på høyt og lavt nivå siden midten av 90-tallet, og han kan fortsatt observeres med nummer på styret i terreng- og cx-ritt.