【问题标题】:Razor view with asp.net core not working带有 asp.net 核心的 Razor 视图不起作用
【发布时间】: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 中有一个基本视图

任何帮助将不胜感激。

谢谢

【问题讨论】:

    标签: razor asp.net-core-mvc


    【解决方案1】:

    真烦人。

    经过数小时的头撞,然后发布问题,在我的“最后一搏”中,我找到了答案。

    在 VSCode 中调试后,我能够得到实际的错误消息。

    然后我找到了Internal Server Error while running a simple .Net Core MVC application on Ubuntu 16.04,这就是答案。

    是时候去尝试找出“preserveCompilationContext”现在实际上做了什么。

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-09
      • 2017-01-22
      • 1970-01-01
      相关资源
      最近更新 更多