Blake Rivell
Blake Rivell

Reputation: 13875

Making an AJAX request to a controller or page model with Razor Pages

With the addition of Razor Pages as an option for .net core I am a bit confused. I am aware that handlers can be used to call multiple actions of the same HTTP type. But what if I want to create an action that will be used across multiple pages.

I am assuming simply creating a controller without a view is the way to go for these actions. I just want to make sure I will be able to call the actions from a razor page w/ jQuery AJAX or a regular button/anchor tag.

I would like the best of both worlds to be available. Should I use the razor pages template and add controllers or use the mvc template and add pages. Or does it not matter.

Upvotes: 0

Views: 2627

Answers (1)

Brad Patton
Brad Patton

Reputation: 4205

I use an API controller for AJAX actions and Razor Pages for the basic GET/POST. If you want to make an AJAX call back to a Razor Page (or even a controller) see the post below about adding the AntiForgery Token to the call.

Example AJAX call back to an ASP.NET Core Razor Page

Upvotes: 1

Related Questions