2017-05-19 12 views
-1

Visual Studio 2017を使用して.NetCore MVCを試し始めました。デフォルトテンプレートを使用して.NetCore MVCアプリケーションを作成しました。 AboutルートをMenuルートに変更したい。したがって、public IActionResult About()をPublic IActionResult Menu()に変更し、About.cshtmlをMenu.cshtmlに変更して正しいビューを取得しました。ただし、テンプレートはこれらの効果を表示していません。言い換えれば、出力内のnavbarは変更されません。以下は私のStartup.csVisual 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が正しく動作しているルートのように見えますが、私はメニューにナビゲーションバーにについてこれを変更し、/ホーム/メニューに私のルートをマップしたいですデフォルトのテンプレートに保存します。

+0

Views/Shared/_Layout.cshtmlにnavbarがあります。手動で変更する必要があります。 – juunas

+0

何らかの理由で、私はそれが自動であると思った。ありがとう! – WOW

+0

お望みなら、それを答えとして追加してください、私はそれを受け入れることができます! – WOW

答えて

0

Views/Shared/_Layout.cshtmlでデフォルトのナビゲーションバーを変更する必要があります。これは、アクション固有のビューがレンダリングされるMVCデフォルトテンプレートの共有レイアウトビューです。

関連する問題