简体   繁体   English

使用控制器名称和动作名称main.js时,asp.net核心出现Angular 2安装问题

[英]Angular 2 setup issue with asp.net core while using controller name and action name main.js not found

I have successfully setup my angular 2 application in asp.net core which is working great. 我已经在asp.net核心中成功设置了我的angular 2应用程序,该应用程序运行良好。 My main.js file is inside the app folder . 我的main.js文件位于app文件夹中

Working fine beacause the default mvc templete is 工作正常,因为默认的MVC Templete是

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

工作精细模板

I am facing a new problem. 我正面临一个新问题。 I have use the achor tag as below. 我使用了如下的achor标签。 ` `

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

Now the navigation URL is http://localhost:28739/Account/Login 现在导航URL为http:// localhost:28739 / Account / Login

In my systemjs.config.js I have mention the main as show below 在我的systemjs.config.js中,我提到了主要内容,如下所示

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

Its works great when there is no controller name and action name in the url. 当URL中没有控制器名称和动作名称时,它的效果很好。 But when their is controller name and action name. 但是当它们是控制器名称和动作名称时。 It gives me a error as main.js not found. 由于找不到main.js,这给了我一个错误。 Below is the image. 下面是图像。

找不到main.js错误

Can anyone please tell me how to solve this issue. 谁能告诉我如何解决这个问题。

Finally Found the solution. 终于找到了解决方案。 Here is the reference link http://blog.nbellocam.me/2016/03/21/routing-angular-2-asp-net-core/ 这是参考链接http://blog.nbellocam.me/2016/03/21/routing-angular-2-asp-net-core/

I have added in startup.cs 我在startup.cs中添加了

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

And add <Head><base href="/" /></Head> in the layout view 并在布局视图中添加<Head><base href="/" /></Head>

在索引页面中使用<base href="/" />

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

相关问题 覆盖ASP.NET Core中的控制器名称 - Override controller name in ASP.NET Core 将控制器操作呈现为字符串(使用虚拟路径,无操作/控制器名称)ASP.NET MVC 3 - Render Controller Action To String (Using Virtual Path, No action/controller name) ASP.NET MVC 3 可以在不事先知道字段名称的情况下将表单提交文件提交到ASP.NET Core控制器吗? - Can form submit file(s) to ASP.NET Core controller action without knowing field name in advance? ASP.NET Core 3.1,从当前HttpContext中的referrer url获取controller和动作名称 - ASP.NET Core 3.1, get the controller and action name from referrer url in the current HttpContext 在 ASP.NET Core 中 Program.Main 中访问环境名称 - Access environment name in Program.Main in ASP.NET Core 如何在ASP.NET MVC中将/ controller / action-name之类的URL路由到controller / action_name - How to route URLs like /controller/action-name to controller/action_name in ASP.NET MVC 在ASP.NET Core Web API中使用依赖项注入时未调用Controller Action方法 - Controller Action method not called while using dependency injection in asp.net core web api 如何覆盖 asp.net mvc 核心中的控制器名称? - How to override Controller's name in asp.net mvc core? Asp.net 核心:使用文件夹名称路由 Controller - Asp.net Core: Route Controller with Folder Name 将Asp.net核心控制器限制为特定域名 - limit Asp.net core controller to specific domain name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM