【发布时间】:2019-11-10 12:55:42
【问题描述】:
我创建了一个 ASP.NET Core Angular 项目。有一个默认的angular组件和一个mvc的HomeController。当我直接运行应用程序时,它工作正常。网页显示角度组件的输出。然后我看HomeController的源码,如下图:
class HomeController
{
// ... some code here
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
return new string[] { "value1", "value2" };
}
// ... some code here
}
到目前为止,我想做的是使用 URL 来调用 Get 方法,而不是使用 ajax 来调用动作。我只是把 URL 放到浏览器的地址栏上。我使用的网址是:/Home/Get。但它不起作用,页面仍然显示角度组件的输出。
那么如何解决这个问题呢?
【问题讨论】:
-
如果浏览器响应 Angular 应用程序,您可能使用了错误的域。 Angular 服务器在开发中运行在 http:localhost:4200 (使用 4200 端口)。您的 ASP.Net 应用程序正在另一个应用程序中运行。
标签: c# node.js angular asp.net-core single-page-application