[英]How to turn ASP .NET WEB APP with Razor Pages into an API?
So, basically I have a blog website that I developed using ASP .NET with Razor Pages but, now I want to implement those blog posts on my personal portfolio website (Built with simple HTML, CSS and JS).所以,基本上我有一个博客网站,我使用 ASP .NET 和 Razor 页面开发,但现在我想在我的个人投资组合网站上实现这些博客文章(使用简单的 HTML、CSS 和 JS 构建)。
My first thought was: Gee, I now need to create an ASP .NET API from scratch to connect to the same blog database and then fetch it all with JS from my Portfolio Website.我的第一个想法是:哎呀,我现在需要从头开始创建一个 ASP .NET API 以连接到同一个博客数据库,然后使用 JS 从我的投资组合网站获取所有内容。
Question: Would I actually need to create a brand new API just for that or is there any way I can turn the existing blog into an API that can be called externally?问题:我真的需要为此创建一个全新的 API 吗?或者有什么方法可以将现有博客变成一个可以从外部调用的 API 吗? Or somehow add an API endpoint that instead of rendering the pages just sends the json data back to the client?
或者以某种方式添加一个 API 端点,而不是呈现页面,只是将 json 数据发送回客户端?
Thanks you all in advance提前谢谢大家
You have three choices:你有三个选择:
JsonResult
and call that from your AJAX methodJsonResult
并从您的 AJAX 方法中调用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.