C# MVC控制器未正确返回视图

C# MVC控制器未正确返回视图,c#,html,asp.net-mvc,asp.net-mvc-3,C#,Html,Asp.net Mvc,Asp.net Mvc 3,我离开这个项目有一段时间了,现在我又回来了,有些东西坏了。当我启动项目时,一个错误显示了我假设的视图中的空对象。我检查了控制器是否返回了错误的视图,但这似乎不是问题所在。我将ViewData标题更改为“Index”,但这也不起作用。我甚至使用了端点,但它也不起作用({controller=Home}/{action=Index}/{id?})是它当前所在的位置。有人对这个项目可能出了什么问题有什么建议吗 显示错误 NullReferenceException:对象引用未设置为 对象Index.c

我离开这个项目有一段时间了,现在我又回来了,有些东西坏了。当我启动项目时,一个错误显示了我假设的视图中的空对象。我检查了控制器是否返回了错误的视图,但这似乎不是问题所在。我将ViewData标题更改为“Index”,但这也不起作用。我甚至使用了端点,但它也不起作用({controller=Home}/{action=Index}/{id?})是它当前所在的位置。有人对这个项目可能出了什么问题有什么建议吗

显示错误

NullReferenceException:对象引用未设置为 对象Index.cshtml中的AspNetCore.Views\u Home\u Index.ExecuteAsync(), 第9行

索引页如下所示

@using InTheCloud.Models
@using System.IO
@using Microsoft.AspNetCore.Http;
@using System
@model IndexViewModel

@{ ViewData["Title"] = "Home Page"; }


<script type="text/javascript" src="~/Scripts/jquery- 
3.5.1.min.js"></script>

<head>
 <link rel="stylesheet" type="text/css" 
  href="~/css/indexstylesheet.css">
</head>
...
using Microsoft.Extensions.Logging;
using InTheCloud.Models;
using InTheCloud.Views.PaymentPage;
using System.IO;
using System.Drawing;
using System.Text.RegularExpressions;
using Services;

namespace InTheCloud.Controllers
{
    
    public class HomeController : Controller
    {

        private readonly ILogger<HomeController> _logger;
        private string CurrentFolder = "wwwroot/UploadedFiles";

        public HomeController(ILogger<HomeController> logger)
        {

            _logger = logger;
        }

        public IActionResult Index()
        {
            IndexViewModel IVM = new IndexViewModel();
            return View("Index", IVM);
        }

        public IActionResult Privacy()
        {
            PrivacyViewModel PVM = new PrivacyViewModel();
            return View("Privacy", PVM);
        }

        public IActionResult MyFiles()
        {
            MyFilesViewModel MFVM = new MyFilesViewModel();
            MFVM.CurrentFolder = CurrentFolder;
            MFVM.ItemsList = (List<MyFilesViewModel.Item>)GetFiles();
            return View("MyFiles", MFVM);
        }
...
控制器看起来像这样

@using InTheCloud.Models
@using System.IO
@using Microsoft.AspNetCore.Http;
@using System
@model IndexViewModel

@{ ViewData["Title"] = "Home Page"; }


<script type="text/javascript" src="~/Scripts/jquery- 
3.5.1.min.js"></script>

<head>
 <link rel="stylesheet" type="text/css" 
  href="~/css/indexstylesheet.css">
</head>
...
using Microsoft.Extensions.Logging;
using InTheCloud.Models;
using InTheCloud.Views.PaymentPage;
using System.IO;
using System.Drawing;
using System.Text.RegularExpressions;
using Services;

namespace InTheCloud.Controllers
{
    
    public class HomeController : Controller
    {

        private readonly ILogger<HomeController> _logger;
        private string CurrentFolder = "wwwroot/UploadedFiles";

        public HomeController(ILogger<HomeController> logger)
        {

            _logger = logger;
        }

        public IActionResult Index()
        {
            IndexViewModel IVM = new IndexViewModel();
            return View("Index", IVM);
        }

        public IActionResult Privacy()
        {
            PrivacyViewModel PVM = new PrivacyViewModel();
            return View("Privacy", PVM);
        }

        public IActionResult MyFiles()
        {
            MyFilesViewModel MFVM = new MyFilesViewModel();
            MFVM.CurrentFolder = CurrentFolder;
            MFVM.ItemsList = (List<MyFilesViewModel.Item>)GetFiles();
            return View("MyFiles", MFVM);
        }
...
使用Microsoft.Extensions.Logging;
使用云计算模型;
在cloud.Views.payment页面中使用;
使用System.IO;
使用系统图;
使用System.Text.RegularExpressions;
使用服务;
名称空间:cloud.Controllers
{
公共类HomeController:控制器
{
专用只读ILogger\u记录器;
私有字符串CurrentFolder=“wwwroot/UploadedFiles”;
公共家庭控制器(ILogger记录器)
{
_记录器=记录器;
}
公共IActionResult索引()
{
IndexViewModel IVM=新IndexViewModel();
返回视图(“索引”,IVM);
}
公共IActionResult隐私()
{
PrivacyViewModel PVM=新PrivacyViewModel();
返回视图(“隐私”,PVM);
}
公共IActionResult MyFiles()
{
MyFileViewModel MFVM=新的MyFileViewModel();
MFVM.CurrentFolder=CurrentFolder;
MFVM.ItemsList=(List)GetFiles();
返回视图(“MyFiles”,MFVM);
}
...

在我的一个模型中找到了它。问题已经解决,但我想知道显示的错误是否真的描述了存在的错误。我认为有人可以在错误捕获消息方面做得更好!