I'm trying to create a minimal MVC6 (I guess MVC Core now?) project in Visual Studio 2015, by starting with an empty project and adding the MVC bits - I don't need a lot of the extra guff that's added as part of the "Web App" project, and I want to learn by doing, so am trying the following method. Unfortunately every request to this web app results in a 500 internal error response with no further details.
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddMvc(); // ADDED } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app) { app.UseIISPlatformHandler(); // REMOVED // app.Run(async (context) => // { // await context.Response.WriteAsync("Hello World!"); // }); app.UseMvc(config => { config.MapRoute("Default", "{controller}/{action}/{id?}", new { controller = "Home", action = "Index" }); }); } // Entry point for the application. public static void Main(string[] args) => WebApplication.Run<Startup>(args); }
public class HomeController : Controller { // GET: /<controller>/ public IActionResult Index() { return View(); } }
@{ Layout = "_Layout"; }
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>My Test App</title> </head> <body> <div> Testing </div> </body> </html>
@{ ViewBag.Title = "My Test App"; } <div>Testing</div>
But when I run this, I get a 500 Internal error response for every request, with no error messages or content that I can see to indicate what might be wrong? Any ideas what may be wrong here?
Well, I have my answer to this. I actually found it as I putting the finalising touchs on the question, so I thought I'd post them if anyone else has similar issues. It seems that if you forget to put a @RenderBody call in _Layout.cshtml, then you get a 500 internal error and nothing obvious that tells you what is wrong! The fix was just to add the @RenderBody() to _Layout.cshtml:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>My Test App</title>
</head>
<body>
<div>
@RenderBody()
</div>
</body>
</html>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.