我创建了我的dotnet 7 react应用程序,使用:
dotnet new react -o my-new-app
字符串
基于:https://learn.microsoft.com/en-us/aspnet/core/client-side/spa/react?preserve-view=true&tabs=netcore-cli&view=aspnetcore-7.0
现在,以下是:
https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/adding-controller?view=aspnetcore-7.0&tabs=visual-studio-code的
我尝试添加名为UserInfoController.cs的控制器(在Controllers文件夹中创建)
using Microsoft.AspNetCore.Mvc;
using System.Text.Encodings.Web;
namespace my-new-app.Controllers;
public class UserInfoController : Controller
{
public string Index()
{
return "Default Action for User Controller";
}
public string Welcome()
{
return "The is the Welcome Action";
}
}
型
然而,每当我运行调用的链接时,
https:// ..... /UserInfo
型
我得到的回应是:
No routes matched location "/UserInfo"
型
应用程序仍然在运行。我还有:
app.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
型
我错过了什么吗?
1条答案
按热度按时间8wigbo561#
您需要将路由添加到“clientApp”中的setupProxy.js
例如,我创建了一个API控制器来返回路由为“/API/values/test”的字符串
字符串
转到客户端应用程序,打开“setupProxy.js”
x1c 0d1x的数据
将
"/api/values/test"
添加到“上下文”数组中的
现在你可以毫无问题地参观路线。
的
您也可以像这样代理整个“values”控制器
的