简体   繁体   English

是否有可能在 ASP.NET 核心 ZE405C1DF83BD248A07FC9A91227

[英]Is it possible to have something similar to Next.js API routes in ASP.NET Core Razor Pages?

I'm developing some applications using ASP.NET Core Razor Pages.我正在使用 ASP.NET Core Razor Pages 开发一些应用程序。 And I know that many times I need to connect to backend only to send and receive data, and no view is in the process.而且我知道很多时候我只需要连接到后端来发送和接收数据,而过程中没有任何视图。

NEXT.js has the concept of api route which works perfectly for this scenario. NEXT.js 具有api route的概念,非常适合这种情况。

Do we have something similar in ASP.NET Core Razor Pages? ASP.NET Core Razor 页面中是否有类似的东西?

Sure, you do not need to return a View in your controller methods, you can return JSON too当然,您不需要在 controller 方法中返回视图,您也可以返回 JSON

public JsonResult ReturnJSONMethod()
{
    return Json(...);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM