如何使用Asp.Net Core空白模板快速搭建基于Mvc的架构?
- 内容介绍
- 文章标签
- 相关推荐
本文共计176个文字,预计阅读时间需要1分钟。
一、创建一个空的MVC项目
二、手动创建Controllers、Models、Views
三、注入MVC服务:public void ConfigureServices(IServiceCollection ServiceCollection) { ServiceCollection.AddMvc(); }
四、注入MVC中间件,并配置路由规则:public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseRouting(); app.UseEndpoints(endpoints=> { endpoints.MapControllerRoute(default, {controller=Home}/{action=Index}/{id?}); }); }
二 手动创建Controllers、Models、Views
三 注册MVC服务
public void ConfigureServices(IServiceCollection ServiceCollection) { ServiceCollection.AddMvc(); }
四 注册MVC中间件,并配置路由规则
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc((RouteBuilder) => { RouteBuilder.MapRoute("default", "{Controller}/{Action}/{Parameter}", new { @Controller = "Home", @Action = "Index", @Parameter = String.Empty }); }); }
五 创建控制器Home与Index视图
六 运行项目 ok
本文共计176个文字,预计阅读时间需要1分钟。
一、创建一个空的MVC项目
二、手动创建Controllers、Models、Views
三、注入MVC服务:public void ConfigureServices(IServiceCollection ServiceCollection) { ServiceCollection.AddMvc(); }
四、注入MVC中间件,并配置路由规则:public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseRouting(); app.UseEndpoints(endpoints=> { endpoints.MapControllerRoute(default, {controller=Home}/{action=Index}/{id?}); }); }
二 手动创建Controllers、Models、Views
三 注册MVC服务
public void ConfigureServices(IServiceCollection ServiceCollection) { ServiceCollection.AddMvc(); }
四 注册MVC中间件,并配置路由规则
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc((RouteBuilder) => { RouteBuilder.MapRoute("default", "{Controller}/{Action}/{Parameter}", new { @Controller = "Home", @Action = "Index", @Parameter = String.Empty }); }); }
五 创建控制器Home与Index视图
六 运行项目 ok

