【发布时间】:2017-03-21 11:32:10
【问题描述】:
我仍在尝试了解 asp.net core,所以这可能是一个愚蠢的问题,但我无法获得使用 asp.net core mvc 的清晰视图。
当我尝试返回视图并且在控制台日志记录中没有得到任何有用的信息时,我收到了 500 错误。
我的项目.json:
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
},
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.Extensions.DependencyInjection": "1.0.0",
"Microsoft.AspNetCore.Mvc.Razor": "1.0.1",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0"
},
"imports": "dnxcore50"
}
}
}
程序.cs:
using System;
using System.IO;
using Microsoft.AspNetCore.Hosting;
namespace aspnetcoreapp
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.Build();
host.Run();
}
}
}
Startup.cs:
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.Logging;
namespace aspnetcoreapp
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(LogLevel.Debug);
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
});
app.Run(context =>
{
return context.Response.WriteAsync("Hello from ASP.NET Core!");
});
}
}
}
Home.cs:
using Microsoft.AspNetCore.Mvc;
//using System.Text.Encodings.Web;
namespace MvcMovie.Controllers
{
public class HomeController : Controller
{
//
// GET: /HelloWorld/
public IActionResult Index()
{
return View();
}
//
// GET: /HelloWorld/Welcome/
public string Welcome()
{
return "This is the home Welcome action method...";
}
}
}
我在 /Views/Home/Index.cshtml 中有一个基本视图
任何帮助将不胜感激。
谢谢
【问题讨论】: