-1
我剛剛開始嘗試使用Visual Studio 2017的.NetCore MVC。我使用默認模板創建了一個.NetCore MVC應用程序。我想要將關於路線更改爲菜單路線。因此,我將公開的IActionResult About()更改爲公共IActionResult Menu(),並將About.cshtml更改爲Menu.cshtml以獲取正確的視圖。但是,該模板沒有顯示這些效果。換句話說,輸出中的導航欄不會改變。以下是我的Startup.cs如何在Visual Studio 2017的默認模板中更改路由?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace RouteCheck
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
和我的輸出看起來像這樣The output by default template路線/Home/Menu工作正常,但我想在導航欄來改變這種關於對菜單和我的路線圖到/ home /菜單在默認模板中。
您可以在Views/Shared/_Layout.cshtml中找到導航欄。你將不得不手動修改它。 – juunas
出於某種原因,我認爲這是自動的。謝謝! – WOW
如果你想請添加它作爲答案,我可以接受它! – WOW