將以下內容添加到您的Startup.cs中以獲得MVC運行。
public void ConfigureServices(IServiceCollection services)
{
services.ConfigureRouting(
routeOptions =>
{
// All generated URL's should append a trailing slash.
routeOptions.AppendTrailingSlash = true;
// All generated URL's should be lower-case.
routeOptions.LowercaseUrls = true;
});
services.AddMvc();
}
public void Configure(IApplicationBuilder application)
{
application.UseMvc();
}
屬性路由默認情況下添加,這樣你就可以使用[Route]
和/或[HttpGet]
/[HttpPost]
屬性來代替。
[Route("[controller]")] // [controller] is replaced by 'car'.
public class CarController : Controller
{
[Route("hello")] // Or use [HttpGet]
public string World()
{
return "World";
}
}
舊學校路由需要更多的工作。你必須在Startup.cs添加路由
application.UseMvc(routes =>
{
routes.MapRoute(
name: "route1",
template: "hello",
defaults: new { controller = "Car", action = "World" });
});
如果你需要mvc6/asp.net之前出貨的mvc5應用程序,你不能使用mvc5用asp.net 5.5是準備好你不應該嘗試使用任何部分asp.net 5. –
[ASP.NET MVC Boilerplate](https://visualstudiogallery.msdn.microsoft.com/6cf50a48-fc1e-4eaf-9e82-0b2a6705ca7d)可以幫助你找出如何更快地翻譯你的代碼。它具有比標準項目模板更多的開箱即用功能。 –