gpt4 book ai didi

c# - 使用 Controller 名称和操作名称 main.js 时,asp.net core 的 Angular 2 设置问题

转载 作者:太空宇宙 更新时间:2023-11-03 15:10:26 26 4
gpt4 key购买 nike

我已经在 asp.net core 中成功设置了我的 angular 2 应用程序,它运行良好。 我的 main.js 文件在应用程序文件夹中

工作正常,因为默认的 mvc 模板是

 app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});

working fine template

我遇到了一个新问题。我使用了如下的 achor 标签。 `

<li><a asp-controller="Account" asp-action="Login">Login </a></li>

现在导航 URL 是 http://localhost:28739/Account/Login

在我的 systemjs.config.js 中,我提到了主要内容,如下所示

 packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
},
'angular2-in-memory-web-api': {
main: './index.js',
defaultExtension: 'js'
}
}

当 url 中没有 Controller 名称和操作名称时,它工作得很好。但是当它们是 Controller 名称和操作名称时。它给了我一个错误,因为找不到 main.js。下面是图片。

error of main.js not found

谁能告诉我如何解决这个问题。

最佳答案

终于找到解决办法了。这是引用链接 http://blog.nbellocam.me/2016/03/21/routing-angular-2-asp-net-core/

我在startup.cs中添加了

routes.MapRoute(
name: "spa-fallback",
template: "{*url}",defaults: new { controller = "Home", action = "Index" });

并添加<Head><base href="/" /></Head>在布局 View 中

关于c# - 使用 Controller 名称和操作名称 main.js 时,asp.net core 的 Angular 2 设置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41405439/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com