为什么我收到内部服务器错误和这个错误列表,我应该关注什么来修复我收到的错误?

时间:2017-11-20 13:08:08

标签: asp.net-mvc

一个控制器,它返回姓氏以方法中给出的字母开头的姓名。

using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using AdminController.Models;

    namespace AdminController.Controllers
    {
        public class HomeController : Controller
        {
            public IActionResult Index(string letter)
            {
                string query = "";
                if(letter != null) { query = letter; }

                List<Student> studenten = new List<Student>()
                {
                 new Student { Naam = "Johan", Achternaam = "Jacobs" },
                 new Student { Naam = "Karel", Achternaam = "Jay" },
                 new Student { Naam = "John", Achternaam = "Jas" }
                };
                List<Student> NieuwStudenten = null;
                NieuwStudenten = studenten.Where(x => x.Achternaam.StartsWith(query) == true).ToList();

                ViewData["NieuwStudenten"] = NieuwStudenten;

                return View(NieuwStudenten);
        }


    }
    }



// View
    @using AdminController.Models;
    @model AdminController.Models.Student;

    @{var lijst = (List<Student>)ViewData["NieuwStudenten"];}

    <html>

    <body>
    @foreach (var item in lijst)
    {
        <h1>
            @item.Naam, @item.Achternaam
        </h1>
    }
    </body>

    </html>


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;

    namespace AdminController.Models
    {
        public class Student
        {
            public string Naam { get; set; }
            public string Achternaam { get; set; }
        }
    }

这些是我收到的错误。

An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.

Generated Code

Syntax error, ',' expected
+
    public class _Views_Home_Index_cshtml : Microsoft.AspNetCore.Mvc.Razor.RazorPage<AdminController.Models.Student;>
Syntax error, '>' expected
+
        public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<AdminController.Models.Student;> Html { get; private set; }
Invalid token ';' in class, struct, or interface member declaration
+
        public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<AdminController.Models.Student;> Html { get; private set; }
Invalid token '{' in class, struct, or interface member declaration
+
        public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<AdminController.Models.Student;> Html { get; private set; }
Invalid token '{' in class, struct, or interface member declaration
+
        public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<AdminController.Models.Student;> Html { get; private set; }
Invalid token ';' in class, struct, or interface member declaration
+
        public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<AdminController.Models.Student;> Html { get; private set; }
Invalid token ';' in class, struct, or interface member declaration
+
        public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<AdminController.Models.Student;> Html { get; private set; }
Invalid token ';' in class, struct, or interface member declaration
+
        public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<AdminController.Models.Student;> Html { get; private set; }
Invalid token ';' in class, struct, or interface member declaration
+
        public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<AdminController.Models.Student;> Html { get; private set; }
Type or namespace definition, or end-of-file expected
+
}
A namespace cannot directly contain members such as fields or methods
+
        public override async Task ExecuteAsync()
'<invalid-global-code>.ExecuteAsync()': no suitable method found to override
+
        public override async Task ExecuteAsync()
'_Views_Home_Index_cshtml' does not implement inherited abstract member 'RazorPage.ExecuteAsync()'
+
    public class _Views_Home_Index_cshtml : Microsoft.AspNetCore.Mvc.Razor.RazorPage<AdminController.Models.Student;>
The name 'BeginContext' does not exist in the current context
+
            BeginContext(0, 2, true);
The name 'WriteLiteral' does not exist in the current context
+
            WriteLiteral("\r\n");
The name 'EndContext' does not exist in the current context
+
            EndContext();
The name 'BeginContext' does not exist in the current context
+
            BeginContext(130, 2, true);
The name 'WriteLiteral' does not exist in the current context
+
            WriteLiteral("\r\n");
The name 'EndContext' does not exist in the current context
+
            EndContext();
The name 'BeginContext' does not exist in the current context
+
            BeginContext(265, 20, true);
The name 'WriteLiteral' does not exist in the current context
+
            WriteLiteral("\r\n<html>\r\n\r\n<body>\r\n");
The name 'EndContext' does not exist in the current context
+
            EndContext();
The name 'BeginContext' does not exist in the current context
+
            BeginContext(318, 18, true);
The name 'WriteLiteral' does not exist in the current context
+
            WriteLiteral("    <h1>\r\n        ");
The name 'EndContext' does not exist in the current context
+
            EndContext();
The name 'BeginContext' does not exist in the current context
+
            BeginContext(337, 9, false);
The name 'EndContext' does not exist in the current context
+
            EndContext();
The name 'BeginContext' does not exist in the current context
+
            BeginContext(346, 2, true);
The name 'WriteLiteral' does not exist in the current context
+
            WriteLiteral(", ");
The name 'EndContext' does not exist in the current context
+
            EndContext();
The name 'BeginContext' does not exist in the current context
+
            BeginContext(349, 15, false);
The name 'EndContext' does not exist in the current context
+
            EndContext();
The name 'BeginContext' does not exist in the current context
+
            BeginContext(364, 13, true);
The name 'WriteLiteral' does not exist in the current context
+
            WriteLiteral("\r\n    </h1>\r\n");
The name 'EndContext' does not exist in the current context
+
            EndContext();
The name 'BeginContext' does not exist in the current context
+
            BeginContext(380, 18, true);
The name 'WriteLiteral' does not exist in the current context
+
            WriteLiteral("</body>\r\n\r\n</html>");
The name 'EndContext' does not exist in the current context
+
            EndContext();

Show compilation source
/Views/Home/Index.cshtml

The name 'ViewData' does not exist in the current context
+
@{var lijst = (List<Student>)ViewData["NieuwStudenten"];}
The name 'Write' does not exist in the current context
+
        @item.Naam, @item.Achternaam
The name 'Write' does not exist in the current context
+
        @item.Naam, @item.Achternaam

当然我不希望任何人修复此代码或为我检查所有错误我的问题具体实际上是我做错了什么以及为什么我收到所有这些错误以及我应该继续纠正它们的方向? 我对MVC和C#很新,我的情况是我基本上无法理解出了什么问题。

感谢您的投入,并提醒我,我不希望您为我做奴隶劳动,我所需要的只是朝着正确的方向努力。

1 个答案:

答案 0 :(得分:0)

如果您遇到此类错误,请转到IE中的开发人员工具(单击F12),然后转到网络单击开始按钮。你可以看到HTTP响应代码。单击任何响应代码(例如:500),然后转到响应正文,您可以获取错误详细信息。我希望这会对你有所帮助。找到附图,你可以清楚地理解。